Jump to content

Recommended Posts

Posted

I try to modify the player model and give the player a hat when a certain condition is: true.

 

What works:

The hat is rendered fine and moves with the player (checked with f5 view / backview).

Looking to the left and right (yaw angle) rotate the hat correct.

 

The problem:

When looking up/down, the head rotates on the pitch angle, but i don't know how to pitch the corresponding hat too, it just stays right above the player model

without rotating with the head up and down.

 

The rotation is done inside a RenderCustomPlayer.class which overwrites the vanilla RenderPlayer.class

 

Corresponding classes:

1. ModelHat (just block for testing purposes)

2. RenderCustomPlayer extends RenderPlayer (checks boolean

 

RenderCustomPlayer.class


@SideOnly(Side.CLIENT)
public class RenderCustomPlayer extends RenderPlayer
{
private ModelHat hat;

public RenderCustomPlayer()
{
	super();
	hat = new ModelHat();
}

@Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTickTime)
{
	super.doRender(entity, x, y, z, yaw, partialTickTime);
       
	//boolean check for testing purposes
	if(1==1)
	{
		this.renderHat((EntityPlayer)entity, x, y, z, yaw, partialTickTime);
	}
}

 public void renderHat(EntityPlayer player, double x, double y, double z, float yaw, float partialTickTime)
    {
        GL11.glPushMatrix();
        	GL11.glTranslatef((float)x, (float)y-0.04F, (float)z);
        GL11.glRotatef(180F-yaw, 0F, 1F, 0F);
        GL11.glScalef(-1.0F, -0.8F, 1.0F);   

        Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("testmod", "textures/npc/Hat.png"));
        hat.render(player, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0525F);
        
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }
}

 

Screenshots:

 

Rendering fine when looking to the left and right (turning with the player head on horizontal axis)

ZBbY1xC.png

 

Problem here: not rotating on the vertical axis with the player hat :(

8609hME.pngB2i1nYn.png

 

Can somebody help me out how to rotate it on the vertical axis too?

 

 

Thanks in advance

 

StreakyFox

Posted

You should use RenderPlayer.Post ;)

 

For this rotation, I think you'll need

GL11.glRotatef(some_value, 0.0F, 0.0F, 1.0F);

and also some

GL11.glTranslatef(other_value, 0.0F, 0.0F);

Posted

I already use these two:

 

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

                -> translates the box exactly above the playerhead

 

        GL11.glRotatef(f1, f2, f3, f4);

                -> not sure about the rotations in here, my thoughts after some testing:

                f1 = Angle to rotate;

                f2 = rotation around X-Axis;

                f3 = rotation around Y-Axis;

                f4 = rotation around Z-Axis;

             

 

                GL11.glRotatef(180F-yaw, 0F, 1F, 0F);

                rotates perfect around horizontal axis when looking left / right.

 

        //GL11.glDisable(GL11.GL_TEXTURE_2D);

 

The problem is: i need the angle on which the player looks up/down, but dont know where to get that from.

Posted

Well, with the entity instance.

//in Entity:
    public float rotationYaw;
    public float rotationPitch;
    public float prevRotationYaw;
    public float prevRotationPitch;

Posted

i managed to get the rotation working for the pitch and yaw but still needs some tweaking since the hat is still fixed on the location above the head, only rotating instead of moving with the head when looking up and down. Any suggestions?

Posted

You use a little thing called trigonometry.

Sin and Cos can be used for finding how much to offset the position of the hat.

Pm me if you need help  ;)

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

For moving the hat across the x and z you would do...

add cos((float)((double)(-rotationYaw/180F)* Math.PI)) to x

add sin((float)((double)(-rotationYaw/180F)* Math.PI)) to z

Note: it might be subtract instead :P

 

Do something similar for the y offset

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

        GL11.glRotatef(f1, f2, f3, f4);

                -> not sure about the rotations in here, my thoughts after some testing:

                f1 = rotation around X-Axis;

                f2 = rotation around Y-Axis;

                f3 = rotation around Z-Axis;

                f4 = no effect ??

f1 is the rotation angle, of all following angles:

f2 is how much of the angle given at f1 will be rotated on the X-axis (so if f1 is 90 degrees, a value of 0.5 in f2 wil result in a 45 degree rotation on the X-axis).

f3 and f4 are the same for the Y- and Z-axis.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

i tried something like:

 

yOffset = 0.4F*sin(player.prevRotationPitch);

GL11.glTranslatef(yOffset, 0F, 1F, 0F);

 

Which did not work as i wanted^^

All this animation thingy seems to confusing to me, is there anyone around here who can can teach

me the details of rendering tools and armor around a playermodel and animations?

Posted

Me again:

i finally figured out how to render additional extras like backpacks etc on the player BUT i have some texturing problems now

 

The screenshot here shows an example:

The green box is a simple textured rectangle that should be rendered on the left shoulder.

 

The red marked little textures thingies are the rendering errors, could someone help me to get rid of these or tell me what is going on?

 

Nevermind, i got everything working fine!

Man, that was quiete difficult to figure out! :D

 

We3m4LC.png

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.