Game Development Community

Vector Math

by Derk Adams · in Technical Issues · 11/28/2004 (9:17 pm) · 5 replies

Greetings,

I have searched the forum and been unable to find an answer to my question. I am working in script for this.

I am looking to add a displacement value to a 3d point based on a direction vector.

I have a vector [%direction] (normalized) that is the "local axis" pointing in the local Z direction. I have a point in space [%position]. I would like to 0.1 meters to the X local axis, not the global one.

I am trying to turn %direction by 90 degrees to have a normalized vector pointing in the local X axis. I would then scale it by 0.1 and add it to %position to get my result.

The problem is, everything I find is dealing with two vectors to find a rotation and I have one vector and a rotation and want the second vector.

Thanks.

#1
11/29/2004 (12:11 am)
Derk,

I'm confused by exactly what you need here.

If all you want to generate is a perpendicular vector (90-deg), no matter how many dimensions, there's a simple way of doing this.

MathWorld - Perpendicular Vector
Game-Dev - Vector Primer.

- Melv.
#2
11/29/2004 (6:10 am)
Melv,

Well, looking at the resources (again :) I noticed that can't do what I am asking because there are an infinite number of 3d vectors perpendicular to a 3d vector.

So, let me restate my request.

I am trying to create a grid of projectiles (think multiple missile launcher). I have the vector of the muzzlepoint and need to offset the next projectile based on the orientation of the weapon. If I just add to the projectile start position, the grid is oriented to the world axis, not the weapon axis.

It looks like I need to get the rotation from the muzzlepoint (don't know how to), and convert it to a vector (don't know how to). Then I will have two vectors (local axis forward and local axis up) which I can do a cross on to get the normal (or 90 degree vector).

Any suggestions on how to go about this?

Thanks.
#3
11/29/2004 (6:36 am)
The approach I would take is this. You can figure out the vector you need from the player's orientation. (Unless you've added mod's to allow weapon orientation changes, or I'm missing something, both totally possible). But, you can get the right vector of the player, then scale it as needed. There's a great code snippet here at the bottom of that thread that will give the up, right, and forward vectors of a player.

Hope that helps.
#4
11/29/2004 (8:38 am)
Brian,

Your link was very helpful. Unfortunatly, I have torso twisting so my weapon mount orientations do change. However, I looked at the console methods available for the mountpoints and it turns out that there is a "getSlotTransform" that will put me in the same place as your player resource.

Thanks.
#5
11/29/2004 (9:01 am)
I think you can do something like this:

xAxis = direction x WorldUp

the cross product of the direction and the world up vector gives you the local X axis... or am I wrong?