Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Directx 3D Racing Game (http://www.programmingforums.org/showthread.php?t=15543)

theflamer14 Apr 2nd, 2008 7:43 PM

Directx 3D Racing Game
 
Hi,

For the past few weeks, I've been working on a racing game using directx. My vehicle driving and acceleration are good, however, I'm having a little trouble with the camera movements(the cam is placed behind my vehicle). I'm trying to position the camera so that when turning my vehicle, the camera should still be behind the vehicle, and the vehicle still remains to be the camera target, thereby only changing the yaw of the camera. I've been trying to come up with a solution to this for a few days now. But I'm still unsure of what to do. Any help is appreciated. Thanks in advance!:)

BstrucT Apr 3rd, 2008 12:31 AM

Re: Directx 3D Racing Game
 
Are you using XNA Game Studio to develop your game?

lectricpharaoh Apr 3rd, 2008 1:59 AM

Re: Directx 3D Racing Game
 
I don't know if this will help, but here's a .NET Managed DirectX resource.

BstrucT Apr 3rd, 2008 3:17 AM

Re: Directx 3D Racing Game
 
Thanks for the link lectricpharaoh!

Was looking for something like that myself but couldn't find anything decent.

>BstrucT

theflamer14 Apr 3rd, 2008 11:38 AM

Re: Directx 3D Racing Game
 
Thank you for trying to help, but I have gone through every single one of these tutorials for DirectX. If I get the camera rotations for the car, then my problem will be solved. The site provided above does not have any tutorials on camera movements, but only how to set it up. I'm looking for a certain formula(s) for the camera position.

OpenLoop Apr 3rd, 2008 11:51 AM

Re: Directx 3D Racing Game
 
You need to multiply the camera position vector with the same quaternion you used to rotate the car. Reimers's tutorials should have some insight about this.

http://www.riemers.net/eng/Tutorials...rp/series2.php

theflamer14 Apr 3rd, 2008 5:41 PM

Re: Directx 3D Racing Game
 
Thanks for helping everyone. Although I didn't use quaternions, I got it! This is what it looks like after I modified it:

:

            cameraPosition = new Vector3(Racer.vehiclePosition.X, 1f, Racer.vehiclePosition.Z);
            cameraPosition.X -= (float)(Math.Sin(Racer.angle)) * 2f;
            cameraPosition.Z -= (float)(Math.Cos(Racer.angle)) * 2f;


            cameraTarget = cameraPosition;

            cameraTarget.X += (float)Math.Sin(Racer.angle) * 0.5f;
            cameraTarget.Y += (float)Math.Sin(_pitch) * 0.5f;
            cameraTarget.Z += (float)Math.Cos(Racer.angle) * 0.5f;


This code is from my camera.cs, and "Racer" is my main form with the rendering, and "angle" is increased by a certain amount every time Left/Right is pressed. It looks really good! Thanks for trying to help once again.


All times are GMT -5. The time now is 3:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC