View Full Version : Rotate vector around point?

Caesar

06-22-2000, 12:16 PM

Ok. I'm writing a camera class. I've got the basics figured out. I can position my camera anywhere I want, and I can have it point anywhere I want using a direction-vector.

The problem is this: how do I make the direction-vector jaw and pitch? The vector is normalized. I basically need to rotate it along the Y-axis at point (0,0,0) for the jaw, and around the X-axis (at the same point) for the pitch, right?

But how?

I've spent hours trying to figure this out using tons of trigonometry, but I can't seem to get it to work. This should be a trivial thing, so I hope there's a simple (and fast!) way to do it.

Caesar

06-22-2000, 12:53 PM

Maybe I should clear a few things up here.

I'm using gluLookAt() to position my camera, using a local vector (of 3 floats) as the first three arguments. I use another vector (of 3 floats) that is normalized that defines the direction I'm pointing. I want to be able to have a function called camera::transform() which will simply load the identitymatrix and then do the glutLookAt().

The member variables of the class (direction and position) must therefor be updated before this happens. So I need to be able to rotate the direction vector around the y and x axis to jaw and pitch the direction of the camera.

I could do all this with multiple calls to glRotatef and glTranslatef and forget all about glutLookAt(). But damn it! I want to do it this way! =)

So any help as to how I rotate my direction vector would be aprechiated.

Caesar

06-22-2000, 01:32 PM

Ok. I looked into it some more and I found the matrix to rotate around a certain axis. I feel stupid for posting here before I had a chance to look into it some more.

But the question remains. How do I multiply a vertex with a matrix. We start learning about matrixes next semester so I really don't have a clue about this.

BTW: if anyone knows of a site that will teach me more about matrix-mathematics I would love to get my hands on it.

So a quick answer would do, I want to multiply my vertex (x,y,z) with the following matrix (which is rotation by a along the X-axis right?):

1 0 0 0

0 (cos a)(-sin a) 0

0 (sin a) (cos a) 0

0 0 0 1

How do I do that in C?

Caeser sorry i dont have a url for u,

but go to an ftp search or just altavista and search for otmmatrx.txt or otmmatx.txt and u will have a extremly good document

have fun! http://www.opengl.org/discussion_boards/ubb/smile.gif

drakaza

06-22-2000, 05:45 PM

Originally posted by Caesar:

BTW: if anyone knows of a site that will teach me more about matrix-mathematics I would love to get my hands on it.

Try this:

http://www.foxfiber.net/3dica/3dica.htm

A GREAT page with an introduction into vectors, through to matrix operations, way through to more advanced stuff!!

Enjoy http://www.opengl.org/discussion_boards/ubb/tongue.gif

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.