Jump to content
  • Advertisement
Sign in to follow this  

Vector problem

This topic is 4436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Imagine a clock hand pointing at 2. (A Vector) The up vector to this vector is 11. (normal) Imagine another vector pointing at 2 but the up vector is 5. Now here is my problem, I have an object following a path. Now my camera needs to follow the curve with the correct up vector but at the moment when the camera should be upside down, it isnt. To calculate the coordinate frame for the curve I do this:
// Calcualte Up Vector
Vector look; // Pre calculated

Vector worldUp(0.0,1.0,0.0); // <---------- NEED TO DETERMINE WHEN TO CHANGE THIS VECTOR TO (0.0,-1.0,0.0)

Vector side = crossProduct(worldUp,look);
side.normalise();
Vector up = crossProduct(look,side);





So what method can I use to determine when to use which up vector. Thx

Share this post


Link to post
Share on other sites
Advertisement
The dot-product (also called scalar product) is defined as
a . b := |a| * |b| * cos( < a,b > ) = Σi ( ai * bi )
and since |v| is always positive, the sign of the dot-product depends solely on the sign of the cosine.

So, if b does not differ more than 90° from a, then the sign of the dot-product is positive. If, on the other hand, the angle between a and b is more than 90°, then the dot-product will be negative.

So you can check against the global up vector to determine what of the both cases you have computed at last. Hopefully this helps you.

Share this post


Link to post
Share on other sites
Quote:

a . b := |a| * |b| * cos( < a,b > ) = Σi ( ai * bi )


Any chance that could be explained with a bit less terminology/symbols please?

my dotProduct method is

float dotProduct(Vector v1, Vector v2);

Thx

Share this post


Link to post
Share on other sites
Quote:
Original post by dawberj3
Quote:

a . b := |a| * |b| * cos( < a,b > ) = Σi ( ai * bi )


Any chance that could be explained with a bit less terminology please?

Sure ;)

The middle part only tells one that the dot-product is proportional with the length of the one vector, proportional with the length of the other vector, and last but not least proportional to the cosine of the angle between the both vectors. The latter proportionality is the property of interest for your problem.

For an implementation only the rightmost part is of interest.

float dotProduct(Vector v1, Vector v2) {
return v1.x*v2.x + v1.y*v2.y;
}

for the case of 2D vectors, and similarly

float dotProduct(Vector v1, Vector v2) {
return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
}

for 3D vectors. (And so on for each next dimension.)

[Edited by - haegarr on March 29, 2006 9:39:28 AM]

Share this post


Link to post
Share on other sites
I know how to calculate the dotProduct, but I dont get which dot product I have to calculate with which vectors and then compare what with what?

Share this post


Link to post
Share on other sites
To concretize the problem: Imagine two curves in 3D space. Both curves are placed around the camera. The one curve is a circle oriented horizontally, and the other one vertically. The curves hit each other in 2 points, one just before and one just behind the camera. Now, when the camera tracks an anchor point following the horizontal curve, it should only do heading. On the other hand, when the camera tracks an anchor point following the vertical curve, it should only do pitching. Is that correct?

EDIT:
If so, then the look-at method isn't definite, since there are two possible representations for the backward point (in fact, the whole backward semi-sphere shows this problem). Hence you have to take the way into account with which the camera approaches.

Hence, IMHO you have to investigate the dot-product of the camera's previous up vector and new up vector. If there is a sign reversal then the camera has turned. Doing a 180° roll over the depth vector should correct it.

[Edited by - haegarr on March 29, 2006 9:07:03 AM]

Share this post


Link to post
Share on other sites
Perhaps it will also work to not compute an absolute look-at but incremental rotations.

Say, as soon as the initial look-at has been done, compute the new look-at vector, and then compute the rotation needed to change the now obsolete look-at vector onto the new look-at vector (cross-product for rotation axis, dot-product for angle). Then concatenate the rotation with the current camera orientation to yield in the new camera orientation.

I think this way would work as long as the incremental rotations are relatively small.

Share this post


Link to post
Share on other sites
Actually there is no way you can determine what the upvector or the sideVector of a 3d curve is.

It is like you have a line in space and you want to now the upvector. The answer is a whole bunch of vectors in the plane perpendicular to the line.

The way you did it, you started with saying: "What would be the sidevector if (0.0,1.0,0.0) was the upvector". (So you restricted all the solutions to just one.)
and then you calculated the upvector with viewDirection and sideVector given.

Another way to restrict all the solutions to one solution is this:
A infinitesimal motion can always be split in two components: a tangential and a normal component. These are always perpendicular.
If a force pulls at the camera in the direction of the tangent component the camera would go faster, but the direction the camera moves in would not be altered. If a force pulls at the camera in the direction of the normal component, the direction the camera moves in would alter, but the speed of the camera would stay the same.
This is what i remember of my physics courses.

the equation of your curve is this:
x = f1(s)
y = f2(s)
z = f3(s)
where s is a parameter (for example time) and f1, f2, f3 are functions.

you define the place of the camera:
camera.x = f1(s)
camera.y = f2(s)
camera.z = f3(s)
(you have to fill in the value of s (time?) in the functions)

you define the viewDirection as the tangent component in the point of the curve your camera is in (also named the gradiënt vector (i assume its the same in english as in dutch)):
viewDirection.x = @f1(s)/@s
viewDirection.y = @f2(s)/@s
viewDirection.z = @f3(s)/@s
where @s stands for partial differential

you define the upVector as the normal component
but i can't find immediately how this one is calculated...
maybe tomorrow if you're still interested hehe

if you do it this way, the upVector is the upDirection that a roller coater train must have if it doesn't want to throw all the people out (if there are no safety bars).
I think this is the effect you want to realise?

[Edited by - Kwak on March 30, 2006 7:37:43 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwak
Actually there is no way you can determine what the upvector or the sideVector of a 3d curve is.

I've understood the OP that there is an object following the path, and a fix located camera tracking the object ... in that case the up vector wouldn't be computed from the path. Hmm.

IMHO dawberj3 hasn't given enough information to give a deliberate answer.

Btw: Path definitions exist that provide a twist parameter, so some kinds of pathes have an inherent definition of up.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!