Jump to content

[1.6.4] Rendering details on the playermodel


StreakyFox

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

        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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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.