[gameprogrammer] Re: flight simulation camera
- From: "richard sabbarton" <richard.sabbarton@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Thu, 27 Sep 2007 11:07:06 +0100
Hi There,
I had exactly the same problem recently because I was making some
calculations in the wrong order. The problem was with the glTranslate and
glRotate. I tend to rotate the world around the camera rather than the
camera around the world. So I will first do a glTranslate/rotate to move to
the point you want to draw your plane. Then do a glPushMatrix() and render
the rest of your scene. Once the rest of your scene is drawn then you can
do glPopMatrix() and then render the plane. It should always be right where
you want it to be.
I am just a beginner really. But this is how I would do this. There are
probably better ways.
The problem I ran into was the start point of ammo when firing. I wanted my
bullets to appear to fire from underneath you but, when looking down, they
started right in front of you. And when looking up you couldn't see them
all. Sounds like a similar issue. The problem is that you know the angle
of your plane and you know the distance behind it that you want to move but
what you need calculate is the x,y,z of the camera. In the same way I
needed to calculate the x,y,z of my ammo start point. I wrote the following
code to rotate a 3D point as part of a 3D point class I was working on.
// x,y,z are members of a 3D Point Class as are xRotated
// yRotated and zRotated. We use the rotated points for
// rendering but we leave the original x,y,z unchanged
// to avoid any distortion.
RotatePoint(int DegAroundX, int DegAroundY, int DegAroundZ){
// Define some variables needed to perform the rotation
FLOAT oldx,oldy,oldz,newx,newy,newz,alpha; // We need to use FLOAT
values for accuracy
oldx = x;
oldy = y;
oldz = z;
// ROTATE AROUND Y FIRST;
alpha = (FLOAT)DegAroundY / (FLOAT)57.29578; // We have to divide
Degrees by 57.29578
// to convert to radians
newx = cos(alpha)*oldx - sin(alpha)*oldz;
newy = oldy;
newz = sin(alpha)*oldx + cos(alpha)*oldz;
oldx = newx; // After each rotation we have to ensure
oldy = newy; // that the new values are pushed into the
oldz = newz; // old values because otherwise we will be
// rotating partially rotated values.
// Then Around X;
alpha = (FLOAT)DegAroundX / (FLOAT)57.29578;
newz = cos(alpha)*oldz - sin(alpha)*oldy;
newy = sin(alpha)*oldz + cos(alpha)*oldy;
newx = oldx;
oldx = newx;
oldy = newy;
oldz = newz;
// Then Around Z;
alpha = (FLOAT)DegAroundZ / (FLOAT)57.29578;
newx = cos(alpha)*oldx - sin(alpha)*oldy;
newy = sin(alpha)*oldx + cos(alpha)*oldy;
newz = oldz;
xRotated = newx;
yRotated = newy;
zRotated = newz;
}
I apologise for the minimal comments. cos, sin & tan were giving me a
headache by the time I was done. I started putting a repository of notes
and stuff on my website. You can take a look at it here.
http://www.fullonsoftware.co.uk/main.html. I put them in my Snippets
section. Lots of my beginners stuff about openGL and C++. Plus some
screenshots of my (now stalled) most recent project.
Regards
Richard
On 27/09/2007, Julien Breton <julienbreton@xxxxxxxxxx> wrote:
>
> Thanks for your answer,
>
> My probleme is that my camera don't stay locked to the plane. When I start
> my exe the camera is behind the plane but when I turn the plane around the Y
> axe (in global coordinates) the camera moves but don't stay behind the
> plane. I can always see the plane but on the right (or left) and front at
> the end but I want stay behind the plane.
> It's not easy to explain and sorry for my English.
> I use C++/OpenGL
>
> Julien
>
> > From: david@xxxxxxxxxxx
> > To: gameprogrammer@xxxxxxxxxxxxx
> > Subject: [gameprogrammer] Re: flight simulation camera
> > Date: Thu, 27 Sep 2007 09:40:31 +0200
> >
> > On Thursday 27 September 2007, Julien Breton wrote:
> > >
> > > Hello,
> > >
> > > Do you know where I can find an example of a flight simulation
> > > camera ?
> >
> > What do you mean, exactly?
> >
> > From what I've seen, the basic logic of how the camera works in
> > simulators (flight, racing etc) is that it's simply locked to the
> > vehicle, ie it sits where the pilot/driver would be, looking straight
> > ahead.
> >
> > In racing simulators, it's common to add minor adjustments to the
> > position and view angle of the camera, to hint about the G-forces
> > that are "lost in transmission". (Lost, unless you're using a moving
> > platform, that is.) I suppose you could do that in a flight simulator
> > too, but I can't remember seeing that. X-Plane has a different
> > solution: Blackout and redout is simulated by fading the view to
> > black and red respectively. Simple and effective. (Not very not
> > relevant to racing though, as you'd normally never get that kind of
> > G-forces on the vertical axis in a car for extended periods of time.)
> >
> >
> > //David Olofson - Programmer, Composer, Open Source Advocate
> >
> > .------- http://olofson.net - Games, SDL examples -------.
> > | http://zeespace.net - 2.5D rendering engine |
> > | http://audiality.org - Music/audio engine |
> > | http://eel.olofson.net - Real time scripting |
> > '-- http://www.reologica.se - Rheology instrumentation --'
> >
> > ---------------------
> > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> >
> >
>
> ------------------------------
> Soyez parmi les premiers à essayer Windows Live Mail. Windows Live
> Mail.<http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d>
>
- References:
- [gameprogrammer] flight simulation camera
- From: Julien Breton
- [gameprogrammer] Re: flight simulation camera
- From: David Olofson
- [gameprogrammer] Re: flight simulation camera
- From: Julien Breton
Other related posts:
- » [gameprogrammer] flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- » [gameprogrammer] Re: flight simulation camera
- [gameprogrammer] flight simulation camera
- From: Julien Breton
- [gameprogrammer] Re: flight simulation camera
- From: David Olofson
- [gameprogrammer] Re: flight simulation camera
- From: Julien Breton