Jump to content

[SOLVED] How are rendering parameters determined?


coolAlias

Recommended Posts

While working on my spell-casting entity, I got the spell to render in front of the main entity, but I noticed that its position was not always correct, nor would it ever change position as the main entity turned or moved. This got me thinking and printing stuff to the screen, and I discovered that for the entire time while my spell was rendering (about 20 ticks), the entity's look vector, rotationYaw, and the yaw parameter passed to the doRender method did not ever change.

 

Here's the relevant sections of my entity's render code:

 

// this render class extends RenderLiving
@Override
public void doRender(Entity entity, double dx, double dy, double dz, float yaw, float partialTick) {
	super.doRender(entity, dx, dy, dz, yaw, partialTick); // renders the caster, nothing special here
	if (shouldRenderSpell) {
		renderSpell((EntityCaster) entity, dx, dy, dz, yaw, partialTick);
	}
}

private void renderSpell(EntityCaster caster, double dx, double dy, double dz, float yaw, float partialTick) {
	GL11.glPushMatrix();
	// alpha and stuff
	Vec3 look = caster.getLookVec();
	double vecX = (double)(-MathHelper.sin(caster.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(caster.rotationPitch / 180.0F * (float) Math.PI));
	double vecZ = (double)(MathHelper.cos(caster.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(caster.rotationPitch / 180.0F * (float) Math.PI));
	LogHelper.info("Rendering yaw: " + yaw + " | vecX: " + vecX + " | vecZ: " + vecZ + " | look vector: " + look);
	GL11.glTranslated(dx + vecX, dy + caster.getEyeHeight(), dz + vecZ); // should always be right in front of the caster, but isn't
	// GL11.glTranslated(dx + look.xCoord, dy + caster.getEyeHeight(), dz + look.zCoord); // same poor results
	GL11.glScalef(scale, scale, scale);
	float roll = ((float) caster.getCurrentCastingTime() + partialTick) * 40;
	while (roll > 360) roll -= 360;
	// this stuff all works for rendering the spell spinning around in place
	GL11.glRotatef(yaw, 0, 1, 0);
	GL11.glRotatef(roll, 0.8F, 0F, -0.6F);
	bindTexture(caster.getType().getEntityTexture());
	// etc., nothing interesting after this
}

 

 

Here is some sample output from my logging:

 

[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
// Goes on exactly the same for quite some time
[22:20:52] [server thread/INFO]: Saving and pausing game...
[22:20:52] [server thread/INFO]: Saving chunks for level 'Dungeons'/Overworld
[22:20:52] [server thread/INFO]: Saving chunks for level 'Dungeons'/Nether
[22:20:52] [server thread/INFO]: Saving chunks for level 'Dungeons'/The End
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
// and again, stays exactly the same the entire render cycle
[22:21:12] [server thread/INFO]: Saving and pausing game...

 

 

So I'm curious: if the caster turns, should not his look vector change to match, or at least the caster's rotationYaw as I clearly can see the caster rotating on the screen, so the client is obviously aware of the current rotationYaw, and how is the 'yaw' parameter from the doRender method determined / why would it be identical for over 20 ticks straight?

 

Thanks for any tips,

 

coolAlias

Link to comment
Share on other sites

I've been doing some debugging and here's what I've discovered:

 

The parameters to RenderLiving#doRender(dx, dy, dz, yaw, partialTick) are apparently all relative to the player. dy is usually -1.6200..., becoming more negative if you jump, and both dx and dz appear to be the difference between the entity and the player's position (which implies that dy is also the difference in y position).

 

I'm not sure yet how yaw is determined, but it is not affected by the player's rotation at all - the player spinning around in circles did not change the yaw parameter in the entity's doRender call. In fact, during my last test it stayed exactly at -21.09375 the entire game session... no matter where I stood, which way the spell-casting entity was facing, nothing changed it. I'm at a loss with this one.

 

I still have no idea why the entity's rotationYaw and look vector remain the same for such extended periods of time, either. I can see the entity turning this way and that on the screen, but apparently the rotationYaw is somehow disconnected from it.

 

Needless to say, what I've found is not at all what I expected. Am I missing something glaringly obvious? As it is, I don't see how any object could possibly be rendered in front of an entity, if the parameters are always relative to the on-looking player(s), but clearly it IS possible.

Link to comment
Share on other sites

@TGG Yes, I looked at the renderYawOffset and a host of other fields as well. No dice :P

 

Anyway, shortly after realizing what the dx/dy/dz parameters were, I was able to come up with a solution:

Vec3 vec3 = Vec3.createVectorHelper(dx, dy, dz).normalize();
GL11.glTranslated(dx - vec3.xCoord, dy + caster.getEyeHeight(), dz - vec3.zCoord);

 

This renders the spell perfectly in front of the caster's eyes, though I am not yet sure how well it will work if there are a bunch of players all looking at the entity from different angles... whatever, it looks great in single player, at least! xD

Link to comment
Share on other sites

Interesting.  I've always found look vector trustworthy, but admit I mostly use it for the player not for other entities.  I'll have to try that...

 

I'm also wondering about your statement that "I clearly see the caster rotating on the screen".  One thing to think about is that the actual head of some entities moves independent of the body.  I'm not sure about your entity, but I can see a case where the yaw and look vector were based on the body rotation but not the head.

 

Similarly, if you looked at the rendering / model of the caster itself i *must* have a field that is controlling the rotation of the render so it seems you should be able to hook onto that.

 

Anyway, it seems you have a work around, but like you I hate having something that is not fully understood in my code...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

That's the strange part - both the body and head rotated normally on the screen, not just one or the other, and none of the yaw/renderYaw or any of those variables seemed to be working. I probably just screwed something up in the model, but nothing stood out at me. A problem for another day, perhaps xD

Link to comment
Share on other sites

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.