Sign in to follow this  
NickyP101

3rd Person Perspective

Recommended Posts

NickyP101    146
Just a couple "noob" questions: At the moment im trying to create a 3rd person view. 1. Should i draw the player at the player posision after i translate? Eg:
gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);          // Clear The Screen And The Depth Buffer 

        gl.glLoadIdentity();


        gl.glRotatef(player.direction,0.0f,1.0f,0.0f);//Look Around


        gl.glTranslatef(player.x, player.y, player.z - 10);
        

        
        

        gl.glCallList(terrain);

        //Draw Player
        gl.glBegin(gl.GL_TRIANGLES);
        
            gl.glVertex3f(-player.x,-player.y + .5f,-player.z);//Top
            gl.glVertex3f(-player.x -.5f,-player.y,-player.z);//Left
            gl.glVertex3f(-player.x + .5f,-player.y,-player.z);
            
        gl.glEnd();


2. That renders the player (triangle atm) correctly, but when i rotate on the y axis the triangle also rotates around the y axis - which i expected. Is there away around this? 3. Should i not be rendering the play that way, should i be drawing the player like this:

gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);          // Clear The Screen And The Depth Buffer 

        gl.glLoadIdentity();

        //Draw Player
        gl.glBegin(gl.GL_TRIANGLES);
        
            gl.glVertex3f(0f,-1f,-10f);//Top
            gl.glVertex3f(-1f,-2f,-10f);//Left
            gl.glVertex3f(1f,-2f, -10f);//Right
            
        gl.glEnd();

        gl.glRotatef(player.direction,0.0f,1.0f,0.0f);//Look Around
        gl.glRotatef(10f,1.0f,0.0f,0.0f);

        gl.glTranslatef(player.x, player.y, player.z);
        

        
        

        gl.glCallList(terrain);



I feel that the first way is the proper way but im unsure. With the latter however when i rotate around the y axis i do not lose the triangle. Another question, in a typical 3rd person view at what angle do u look down at the person on the x-axis? Cheers, Nick [Edited by - NickyP101 on June 5, 2005 5:47:47 AM]

Share this post


Link to post
Share on other sites
stroma    218

gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

gl.glLoadIdentity(); //set identity matrix

// render terrain to (0,0,0)
gl.glCallList(terrain);

gl.glPushMatrix(); //push the matrix stack, so that player matrix will not effect the others' ones

//translate then rotate
gl.glTranslatef(player.x, player.y, player.z);
gl.glRotatef(player.direction,0.0f,1.0f,0.0f); //rotate it

DrawPlayer(); //draw it here

gl.glPopMatrix(); // pop the matrix stack




lots of application uses this:
set modelview matrix
push
translate
rotateX, rotateY, rotateZ //or just use a rotation matrix
draw();
pop

Share this post


Link to post
Share on other sites
stroma    218
and for camera, use gluLookAt function. you can calculate the position with simple sin/cos functions and the look point is the player.pos. hope helps..

Share this post


Link to post
Share on other sites

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