PDA

View Full Version : I need a very special Matrix/Cam transformation



hunsoul
04-05-2001, 05:35 AM
Hello Everybody!

I need a VERY special camera tranformation!

I have 3 point.
The first one is the camera position, and the second one is the target of the camera.

Now the camera is looking at the point 2 correctly.

I would like to the camera look to the 3th point.

Normally, i can solve this "problem" with the LookAt function.

But my 3th point is behind camera's back and i would like to look it so that the camera should upside down!

I hope I wrote the problem down clearly... http://www.opengl.org/discussion_boards/ubb/smile.gif

Please help me with some source.!
If necessary i will write my LookAt down.

[This message has been edited by hunsoul (edited 04-05-2001).]

BwB
04-05-2001, 12:39 PM
Ever heard of gluLookAt()?

Hers the source:




void GLAPIENTRY
gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,
GLdouble upz)
{
int i;
float forward[3], side[3], up[3];
GLfloat m[4][4];

forward[0] = centerx - eyex;
forward[1] = centery - eyey;
forward[2] = centerz - eyez;

up[0] = upx;
up[1] = upy;
up[2] = upz;

normalize(forward);

/* Side = forward x up */
cross(forward, up, side);
normalize(side);

/* Recompute up as: up = side x forward */
cross(side, forward, up);

__gluMakeIdentityf(&m[0][0]);
m[0][0] = side[0];
m[1][0] = side[1];
m[2][0] = side[2];

m[0][1] = up[0];
m[1][1] = up[1];
m[2][1] = up[2];

m[0][2] = -forward[0];
m[1][2] = -forward[1];
m[2][2] = -forward[2];

glMultMatrixf(&m[0][0]);
glTranslated(-eyex, -eyey, -eyez);
}



gluLookAt() takes three points as its parameters the position of the camera (eye) the position of the target (center) and something called 'up'. 'Up' is a normailzed vector that points, well, up. If you want the camera upside down, point this down (0,-1,0) if you want the camera rightside, up point this up (0,1,0).

WhatEver
04-05-2001, 12:57 PM
Normally, i can solve this "problem" with the LookAt function.

He said he already tried that BwB.

BwB
04-05-2001, 02:04 PM
Originally posted by hunsoul:
If necessary i will write my LookAt down.


This is what threw me off.

What do you mean by "your" LookAt?

What exactly are you doing? Why doesnt gluLookAt work? What kind of results are you getting?

Korval
04-05-2001, 04:56 PM
At first, I thought he was trying to make the camera look at 2 separate points.

But now I understand that he is saying that the "up" vector is exactly behind the "at" direction. As we know, gluLookAt fails when all three points are co-linear (that is, along the same line).

Unfortunately, there is nothing we can do for you. The only thing that could work is if you find a new direction to be your "up" vector that isn't directly behind the camera.

Nil_z
04-05-2001, 05:47 PM
Just inverse the "up" vector in gluLookAt, then you will be upside down http://www.opengl.org/discussion_boards/ubb/smile.gif

Rudi_P
04-06-2001, 02:19 AM
I don't understand the statement

The "up" vector is exactly behind the "at" direction. As we know, gluLookAt fails when all three points are co-linear (that is, along the same line).

If this means the 'up' vector is parallel to the 'view' vector, what cases would you ever want this?

I always thought the 'up' vector should be perpendicular to the 'view' vector.