Jump to content

Recommended Posts

Posted

Currently my render can render an existing baked model for a block (for example Dirt) at a point in the world.  However, when I rotate the model (GlStateManager.rotate) it rotates relative to one of it's corners.  What I want to do is shift the origin from the corner to the center of the block so that when I do the rotations it will behave the way I want.

 

I am hoping for something easy.  I really don't want to dust off my old math texts to do some fancy math.  I am getting to old for that. :D

Posted

	public void renderParticle(VertexBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX,
		float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {

	final float x = ((float) (this.prevPosX + (this.posX - this.prevPosX) * partialTicks - interpPosX));
	final float y = ((float) (this.prevPosY + (this.posY - this.prevPosY) * partialTicks - interpPosY));
	final float z = ((float) (this.prevPosZ + (this.posZ - this.prevPosZ) * partialTicks - interpPosZ));

	final float xRotation = MathStuff.wrapDegrees(this.xPeriod + this.xRotationRate * partialTicks);
	final float yRotation = MathStuff.wrapDegrees(this.yPeriod + this.yRotationRate * partialTicks);
	final float zRotation = MathStuff.wrapDegrees(this.zPeriod + this.zRotationRate * partialTicks);

	Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

        GlStateManager.enableRescaleNormal();
	GlStateManager.pushMatrix();
	GlStateManager.pushAttrib();

	GlStateManager.translate(x, y, z);
	GlStateManager.scale(this.scale, this.scale, this.scale);

	GlStateManager.rotate(xRotation, 1.0F, 0, 0);
	GlStateManager.rotate(yRotation, 0, 1.0F, 0);
	GlStateManager.rotate(zRotation, 0, 0, 1.0F);
        
        final int i = this.getBrightnessForRender(partialTicks);
        final int j = i % 65536;
        final int k = i / 65536;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j, (float)k);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        final BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
        blockrendererdispatcher.renderBlockBrightness(this.state, 1.0F);
        
        GlStateManager.color(1, 1, 1, 1);
	GlStateManager.popAttrib();
	GlStateManager.popMatrix();
        GlStateManager.disableRescaleNormal();
}

 

This all works except the render "origin" of the block is one of it's corners.  I just want to convince the model that it's actually been shifted so instead of rendering along an axis "0..10" it's something like "-5..5".

Posted

translate(-0.5,-0.5,-0.5)

rotate(x,y,z,w)

translate(0.5,0.5,0.5)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

*Picks himself off the floor - blinks*

 

OK.  Got that working.  What I think happened is that I tried something similar to this but one of the values for the translation was off.  Maybe I need to stop writing code at such late hours of the evening.

 

For posterity here is the updated code:

 

	public void renderParticle(VertexBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX,
		float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {

	final float x = ((float) (this.prevPosX + (this.posX - this.prevPosX) * partialTicks - interpPosX));
	final float y = ((float) (this.prevPosY + (this.posY - this.prevPosY) * partialTicks - interpPosY));
	final float z = ((float) (this.prevPosZ + (this.posZ - this.prevPosZ) * partialTicks - interpPosZ));

	final float pitch = MathStuff.wrapDegrees(this.currentPitch + this.pitchRate * partialTicks);
	final float yaw = MathStuff.wrapDegrees(this.currentYaw + this.yawRate * partialTicks);
	final float roll = MathStuff.wrapDegrees(this.currentRoll + this.rollRate * partialTicks);

	Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

	GlStateManager.enableRescaleNormal();
	GlStateManager.pushMatrix();
	GlStateManager.pushAttrib();

	GlStateManager.translate(x, y, z);
	GlStateManager.scale(this.scale, this.scale, this.scale);

	GlStateManager.rotate(roll, 0, 0, 1.0F);
	GlStateManager.rotate(pitch, 1.0F, 0, 0);
	GlStateManager.rotate(yaw, 0, 1.0F, 0);
	GlStateManager.translate(-0.5F, -0.5F, 0.5F);

	final int i = this.getBrightnessForRender(partialTicks);
	final int j = i % 65536;
	final int k = i / 65536;
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) j, (float) k);

	GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
	final BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
	blockrendererdispatcher.renderBlockBrightness(this.state, 1.0F);

	GlStateManager.color(1, 1, 1, 1);
	GlStateManager.popAttrib();
	GlStateManager.popMatrix();
	GlStateManager.disableRescaleNormal();
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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