Sign in to follow this  

Issues with Push and Pop Matrix

This topic is 408 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
https://youtu.be/2s7U4C_JJ24
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

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

This topic is 408 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this