Jump to content

[Solved][1.7.10] Rendering a cube with scale not working


Alron

Recommended Posts

Hey everyone

 

I've got a small problem with rendering cubes. I have a RenderShot that should render a shot for an EntityShot, and it basically just renders one cube with varying size. Or at least it should.

Here's the code for the renderer:

 

public class RenderShot extends Render{

private ModelBase model = new ModelBase(){};
private ModelRenderer cubeShot;

public RenderShot(){
	model.textureHeight = 32;
	model.textureWidth = 64;

	cubeShot = new ModelRenderer(model);
                cubeShot.addBox(-2F, -2F, -8F, 4, 4, 16);;
                cubeShot.setTextureSize(64, 32);
}

@Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTickTime) {
	EntityShot shot = (EntityShot)entity;

	GL11.glPushMatrix();

	GL11.glTranslatef((float)x, (float)y, (float)z);
	GL11.glScalef(-1F, -1F, 1F);

	Minecraft.getMinecraft().getTextureManager().bindTexture(Textures.Model.ENERGY_SHOT);

                //rotation works
	cubeShot.rotateAngleX = shot.getRenderPitch();
	cubeShot.rotateAngleY = shot.getRenderYaw() - (float)Math.PI * 0.5f;

                //also correctly calculated
		float scale = 0.0625F * shot.getSizeFactor();
	LogHelper.info(scale);
		cubeShot.render(scale);

		GL11.glPopMatrix();
	}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return Textures.Model.ENERGY_SHOT;
}

}

 

The problem is that it doesn't vary the size even though the scale calculation clearly works (I know cause I print it out).  It always renders all shots the same size, either max scale(wich is a scale of 0.0625) or min scale (wich is about 0.015). It might switch from min to max or the other way around when I restart the game, but it always renders every shot the same size.

 

Does anyone have an idea what could cause that?

Link to comment
Share on other sites

If you're using non-vanilla fields for rendering, you need to implement IEntityAdditionalSpawnData to the entity, as on client-side, it constructs using the constructor that only has a world argument, and won't have any non-vanilla data.

 

I'm actually doing that, its not the problem. shot.getSizeFactor() returns the correct value on the client and the server side. As I said, the scale is calculated properly and as far as I can tell it really should work.

Link to comment
Share on other sites

Thanks for the suggestion!

Unfortunately that method doesn't seem to exist in Render (which is the parent of the RenderShot) :(.  The shot is also extends EntityFireball and not EntityLivingBase (should have mentioned that in OP). 

 

The -1 is because this shot is fired from a cannon, the model for which I made in Techne. When I imported it it screwed up the rotations and such so I just started to change values until it looked right. Thats also the reason for the "shot.getRenderYaw() - (float)Math.PI * 0.5f". Will clean all that rotation stuff up later though, its kinda messy right now.

 

The scaling I'm worried about happens here though:

		float scale = 0.0625F * shot.getSizeFactor();
	LogHelper.info(scale);
	cubeShot.render(scale);

Link to comment
Share on other sites

Hi

 

Disclaimer: I've never used the ModelRenderer.

 

However the vanilla code looks like this

 

ModelRenderer::
    public void render(float p_78785_1_)
    {
        if (!this.isHidden)
        {
            if (this.showModel)
            {
                if (!this.compiled)
                {
                    this.compileDisplayList(p_78785_1_);
                }

I think this "compileDisplayList" means that it will accept the scale factor on the first call, but after that it will ignore it (i.e. it caches the display list and doesn't update it again).

 

So I would suggest that you either use GL11.glScalef(factor, factor, factor) before the call to the render(), or if that doesn't work, use multiple copies of ModelRenderer, one for each size of shot.  (Or just discard your cubeShot and generate a fresh one every time you change the size).

 

-TGG

 

Link to comment
Share on other sites

Hi

 

Disclaimer: I've never used the ModelRenderer.

 

However the vanilla code looks like this

 

Code: [select]

 

ModelRenderer::

    public void render(float p_78785_1_)

    {

        if (!this.isHidden)

        {

            if (this.showModel)

            {

                if (!this.compiled)

                {

                    this.compileDisplayList(p_78785_1_);

                }

 

I think this "compileDisplayList" means that it will accept the scale factor on the first call, but after that it will ignore it (i.e. it caches the display list and doesn't update it again).

 

So I would suggest that you either use GL11.glScalef(factor, factor, factor) before the call to the render(), or if that doesn't work, use multiple copies of ModelRenderer, one for each size of shot.  (Or just discard your cubeShot and generate a fresh one every time you change the size).

 

-TGG

 

Hi

yeah it just occured to me that there really was no reason not to do it in glScalef. So I moved it there and it works fine now, thanks!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.