Jump to content
  • Advertisement
Sign in to follow this  
gummby8

Issues with Push and Pop Matrix

This topic is 696 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to rotate a player model in by 90 degrees
 
I do this in a pre and post render event
 
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onRenderPlayer(RenderPlayerEvent.Pre event) {

		if (ModularBosses.instance.playerTarget != null && MBExtendedPlayer.get((EntityPlayer) event.entity).knockdownTime > 0) {
			EntityPlayer player = event.entityPlayer;
			GL11.glPushMatrix();
			GL11.glTranslatef(0, 0.15f, 0);
			GL11.glRotatef(-90, 1, 0, 0);
			GL11.glRotatef(-player.rotationYaw, 0, 0, 1);
			GL11.glRotatef(player.rotationYaw, 0, 1, 0);

			player.motionX = player.motionY = player.motionZ = 0;

		}

	}

	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onRenderPlayer(RenderPlayerEvent.Post event) {
		if (ModularBosses.instance.playerTarget != null && MBExtendedPlayer.get((EntityPlayer) event.entity).knockdownTime > 0) {
			GL11.glPopMatrix();
		}

	}

 
Problem is now when a spectator views the playor being affected, the affected player is moving all backwards in relation to the spectator.
 
Here is a video of the issue
Affected player is on the left and the spectator is on the right.
 
What can I add to the pre render event to counteract the odd movement on the spectator side. I can check if the client is spectator or affected so I just need to know how to translate the push matrix to look normal for the spectators.
 
Any help is appreciated.
Thank you,

Share this post


Link to post
Share on other sites
Advertisement

If you want to use push/pop matrix, you should do it for each object you render like this

pushMatrix
do transformation
render
popMatrix

Don't mix this like this:

Call pre-render-event for all objects
Render all objects
Call post-render-event for all objects

The latter will not work.

 

But, the modern way don't use push/pop matrix at all. Today you have some matrix attached to the object representing its orientation and you do one of the following things:

1. (old way): glLoadMatrix to upload the model matrix

2. (better): upload the matrix as uniform to your shader

3. (even better): upload the matrix to uniform block/memory

 

The easiest way would be glLoadMatrix, as it seems that you are using ancient OpenGL (Version 1.1) now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!