• Advertisement
Sign in to follow this  

3d Open GL Game - How to fix a object to the camera =)

This topic is 2237 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

[color="#DDA0DD"]Hi guys![img]http://cboard.cprogramming.com/images/smilies/redface.png[/img][/color][color="#DDA0DD"] I have successfully created a Player class which shows a player ( lovely cow! [img]http://cboard.cprogramming.com/images/smilies/redface.png[/img][/color][color="#4B0082"][color="#DDA0DD"] ). However, I wanted to make the player be static in the screen, since I wanted to create a racing-supermario like game. Basically what I have now is a camera that goes around but I want to stick it to the player mesh.

Here is some code:

[b]Camera look() function code[/b][/color]
[/color][CODE]void CCamera::Look(){
// Give openGL our camera position, then camera view, then camera up vector
gluLookAt(m_vPosition.x, m_vPosition.y, m_vPosition.z,
m_vView.x, m_vView.y, m_vView.z,
m_vUpVector.x, m_vUpVector.y, m_vUpVector.z);


[/color][CODE]#ifndef _PLAYER_H#define _PLAYER_H

#include "Model_3DS.h"

// This class was made to handle models created for player use.

class Player

Model_3DS playerModel;


void LoadPlayer(); //Method to load player mesh
void DrawPlayer(); //Method to draw player mesh

Player(); // Constructor
virtual ~Player();



[/color][CODE]#include "Player.h"

playerModel.scale = 3.0f;//Scale the model up
playerModel.pos.x = 250.0f;//Set the x position
playerModel.pos.y = 15;//Set the y position
playerModel.pos.z = 400.0f;//Set the z position



void Player::LoadPlayer(){
playerModel.Load("Data/3DS/SecondaryObjects/cow2.3ds"); // Load a 3ds model

void Player::DrawPlayer(){

playerModel.Draw();//Draw tree model

};[/CODE] [color="#4B0082"]
[color="#DDA0DD"]I was thinking that I should call the position of the camera in the player position, but I am not so sure how [/color][/color][color="#DDA0DD"][img]http://cboard.cprogramming.com/images/smilies/frown.png[/img]

[/color][color="#DDA0DD"]If somebody could give me a hand would be great!
Also, if you want to add me on skype so its quicker would be good too ^^: [/color][color="#DDA0DD"][b]natalieberrystraw is my skype[/b].

Thanks in advance! <3[/color]

[color="#9932CC"][b]Natalie xxx[/b][/color]

Share this post

Link to post
Share on other sites
Well without seeing the remaining code I cannot tell you exactly where to put this, but in a nutshell you'd have to change playerModel.pos whenever you update your camera position.

I guess you have some kind of update() or keyboard input handling method where you set the new camera values. There you might want to call a method like player.updatePosition(m_vPosition, m_vView) to put your cow to the respective position and rotate it as well (although the rotation is a bit trickier if you just know the vector and not the angles).

Let us know whether that helps or if you have further questions!

Share this post

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

  • Advertisement