Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


OpenGL opengl problem!

This topic is 6924 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 ripping my hair out here! i have been workign on this for a while but i dont have the brain power to pull it off it seems. i have a virtual world made in opengl. I have the "camera" 6 units above the plane of the world, angled down at 45 degrees, so it looks down on the ground. now when the up arrow is pressed, the camera moves forwards, backwards for down, and rotates when left or right is pressed, like a first person shooter. in the center of the camera view i want to place a sphere. when i press right i want the sphere to move with the camera, but to always stay at the center of the cameras view. here is partly how i have it coded: there is a structure for the camera: struct camera { float position[3] float orientation[3] } where the position array holds the x,y,z coordinates of where the camera is, and the orientation holds, < i believe the angle> there is a time counter, devised like this: queryPerformanceCounter(&CurrentTime); fTime = (float)(currentTime.QuadPart - LastTime.QuadPart)/ FrequencyCounter.Quadpart; then the linear movement functions like this: ftime =+ ftime * fAngularVelocity; deltax =- ftime * sin(degtorad(camera.orientation[1])); deltaz =+ fTime * cos(degtorad(camera.orientation[1])); where angular velocity is increased by 0.8 or decreased by the same if a key is pressed. degtorad converts degrees to radians. for rotation: camera.orientation[1] = ftime * AngularVelocityX where angular velocityx is decreased or increased 18.0 on keystroke. then its rendered: gltranslate(camera.position[0], camera.position[1], camera.position[2]) glrotate(camera.orientation[1], 0.0, 1.0, 0.0) glrotate(camera.orientation[0], 0.0, 0.0, 1.0) glrotate(camera.orientation[2], 1.0, 0.0, 0.0) now how the hell do i get to draw a sphere in the very center of the camera view < or viewing frustrum>? help! The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..

Share this post

Link to post
Share on other sites
You draw the world, then the camera, then the sphere. The sphere should be translated off the camera matrix to appear where you want it at. If I remember correctly, that is how it should work. I might have it backwards, but you need to translate the spheer without zeroing the camera matrix.

I''ve been wrong more than before.

Share this post

Link to post
Share on other sites
Hi cxi,

Whirlwind almost has it (apologies if I am wrong and he is right ). The order is actually: draw sphere, camera transform, draw world.

Now, the way I would draw each frame is like so:

// clear your buffers and load identity matrix into modelview... that's just how I do it

// draw screen-centred object - in your case, sphere
glTranslatef(0, 0, -5) //use whatever z value to move it into the screen

// Do your camera transformation

// Now, draw your world/other objects
for(however many objects)
//local transforms with translate, rotate, etc


This is assuming your sphere coordinates are based around the origin (0,0,0).

Hope that helps (and I didn't cock that up)

squirrels are a remarkable source of protein...

Oops, just checked my code and touched it up a bit

Edited by - Bad Monkey on May 9, 2000 11:33:22 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!