Re: Viewpoint rotating around a sphere
- From: "Alexander Roehnisch" <alexander.roehnisch@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 6 May 2007 01:37:35 +0200
Hi Pete,
I would use gluLookAt, which lets you actually position the camera (in
contrast to what was said in this group before). gluLookAt takes three
3D-vectors as arguments. The first is the position of the eye (the camera),
the second the center to where it is looking at (this would be constant in
your case) and the third is the up direction (changing this, lets your view
roll around the view direction).
In your case the center is constant the position of your model. If you move
the mouse up, you want to change the y-coordinate of the camera, as it
points upwards. The x coordinate would be constant, as you don´t move the
mouse in that direction. Now you have to consider, that you want to move on
a sphere. The formula for a sphere is x^2 + y^2 + z^2 = Radius. This means,
that the z-coordinate follows directly from your x-coordinate, the new
y-coordinate and the radius of the sphere. What is left is the up vector. I
guess, you could can leave the coordinates zero, as it adjusts itself, but I
am not sure about that. So just try it.
I hope this was useful,
Alex
"Pete" <pdavis68@xxxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:ufednTSZ4qbJk6HbnZ2dnUVZ_hynnZ2d@xxxxxxxxxxxxxxx
Okay, I'm still not getting it. I suspect it has to do with the order thatof
I'm doing things.
I've tried a bunch of different orders and I can't seem to quite get it
right. If I take rotation out of the equation altogether, it works fine,
course, except that it doesn't rotateview
Basically I'm drawing a bunch of atoms (gluSphere) and a bunch of bond
(gluCylinder).
so assuming it's something like this:
public void DrawAtoms(AtomCollection atoms)
{
foreach(Atom atom in atoms)
{
GL.glLoadIdentity();
GL.glTranslatef((float)atom.Location.X * 10, (float)atom.Location.Y *
10, (float)(atom.Location.Z * 10) - 100);
GLUquadric q = GL.gluNewQuadric();
GL.gluQuadricDrawStyle(q,GL.GLU_SMOOTH);
GL.gluSphere(q, ((float) atom.Element.CovalentRadius) * 10, 32, 32);
GL.gluDeleteQuadric(q);
}
That all works fine if I use the Identity matrix as the starting point for
each atom. The problem is, I don't want to do the rotation based on the
identity matrix. So how do I apply the rotation matrix that's not based on
the identity matrix but still be able to use the identity matrix for
translating everything?
Or am I going about this all wrong?
Thanks. I really appreciate how helpful you guys have been.
Pete
"Pete" <pdavis68@xxxxxxxxxxxxxxxxxxx> wrote in message
news:l4udna9wNsbNRKbbnZ2dnUVZ_r-onZ2d@xxxxxxxxxxxxxxx
Thank you guys for you help. I'll rework the code to deal with it
properly.
Pete
"Andy V" <nobody@xxxxxxxxxxx> wrote in message
news:tqOdnejGy-jwS6bbnZ2dnUVZ_j6dnZ2d@xxxxxxxxxxxxxx
Pete wrote:
I'm confused. Do I do this on the projection matrix or on the model
imatrix?
I haven't tried it on the model view matrix because I'll have to
reorganize the code a bit to achieve that, so I want to verify before
butgo through the trouble.
You definitely want to do this on the model-view matrix. Reserve the
projection matrix for the basic projection.
I tried doing it on the projection matrix and it doesn't quite work,
theI think that's because my object is centered at 0, 0, -100, while my
view appears to rotate around 0, 0, 0, which makes sense. What seems
really weird is the lighting seems to change on the molecule when I do
this as well, which is not an effect I want. I want the lighting to
remain relative to the model and indeed, I set up the lighting in the
modelview matrix.
That's why you don't want to put rotation/scaling/translation/etc. in
projection matrix -- it confuses the lighting.
--
Andy V
.
- References:
- Viewpoint rotating around a sphere
- From: Pete
- Re: Viewpoint rotating around a sphere
- From: Gabriel
- Re: Viewpoint rotating around a sphere
- From: Pete
- Re: Viewpoint rotating around a sphere
- From: Andy V
- Re: Viewpoint rotating around a sphere
- From: Pete
- Re: Viewpoint rotating around a sphere
- From: Pete
- Viewpoint rotating around a sphere
- Prev by Date: Re: Viewpoint rotating around a sphere
- Next by Date: Re: Viewpoint rotating around a sphere
- Previous by thread: Re: Viewpoint rotating around a sphere
- Next by thread: 3D file format
- Index(es):
Relevant Pages
|