# Orientation - Macromedia Director 3D

Hi, I'm still fairly new to Director 3D. I'm trying to program a canon that shoots a projectile based on where it is facing. The canon can be rotated in the x and z axis. From the rotation, I shoot the projectile using a fixed force. The problem is how do I get the vector of the canon? I felt that it can't be the position, rotation or scale, as I only want the vector of the canon's orientation. I'm trying to apply the above vector to this formula I found for calculating displacement: displacement = (initial velocity * time) ...

1. ## Orientation

Hi, I'm still fairly new to Director 3D. I'm trying to program a canon that
shoots a projectile based on where it is facing.

The canon can be rotated in the x and z axis. From the rotation, I shoot the
projectile using a fixed force. The problem is how do I get the vector of the
canon? I felt that it can't be the position, rotation or scale, as I only want
the vector of the canon's orientation.

I'm trying to apply the above vector to this formula I found for calculating
displacement:
displacement = (initial velocity * time) + (0.5 * acceleration * time * time)

With the above, I hope to substitute the orientation vector of the canon into
"initial velocity" to get my displacement.

darylku Guest

2. ## Re: Orientation

By default, SW3D uses the -Z axis as the "forward" direction, i.e., pointAt()
will align the node's -Z axis toward the target position (a node can be a
model, group, camera, etc.), so something like....

projectileVector = -cannonModel.transform.zAxis

will give you a normalized vector. I always rotate the pivot point of the
model in 3dsmax to match SW3D's coordinate system. So for something like a car
in 3dsmax, I point the Z axis toward the rear, the Y axis upward, the X axis
will point to the passenger side (starboard). Or you can always override
defaults by changing the node's pointAtOrientation property.

nick kang Guest

3. ## Re: Orientation

I have tried out the axis thing and I think I am having a misconception here.
I'm still new to this 3D thing.

When i hardcoded the formula:
-- displacement = (initial velocity * time) + (0.5 * acceleration * time *
time)
displacement = (vector(5,10,0) * time) + (0.5 * -9.81 * time * time)

I get a smooth parabolic trajectory for my projectile.

I thought I could substitute the vector(5,10,0) value in place of my cannon's
zAxis but it seems that my projectile only goes in a straight line.
That must means that I can't use an axis as the "initial velocity" component
in the above equation.

1) is the model.transform.position a direction vector?

2) how do I actually get a value that resemble vector(5,10,0) that correspond
to my cannon's x and y rotation? I need the "initial velocity" component of the
equation to be a variable based on my cannon's rotation.

darylku Guest

4. ## Re: Orientation

try this:

projectileDirection = -cannonModel.transform.zAxis
projectileSpeed = 10
gravityVector = vector(0,-9.81,0)
initialPosition = vector(0,0,0)
displacementPosition = initialPosition + (projectileDirection *
projectileSpeed * time) + (0.5 * gravityVector * time * time)

In your second equation, you're mixing scalar and vector values so you're
probably not getting the results expected. SW3D will evaluate vector + scalar
by adding the scalar value to each member of the vector:
vector(1,2,3) + 10 = vector(11,12,13)

1) no, that's the location of the model's pivot point (typically in worldspace)
2) assuming that you have have the model created so that it's pivot is aligned
with -Z forward, just use the cannonModel.transform.-zAxis as the directional
vector, after you've finished rotating the cannon.

nick kang Guest

5. ## Re: Orientation

have a look

[url]http://www.director-online.com/buildArticle.php?id=1076[/url]
[url]http://www.director-online.com/buildArticle.php?id=1078[/url]
[url]http://www.director-online.com/buildArticle.php?id=1080[/url]
[url]http://www.director-online.com/buildArticle.php?id=1083[/url]

enjoy

Greg

"nick kang" <webforumsusermacromedia.com> wrote in message
news:cgc7na\$oh5\$1forums.macromedia.com...
> try this:
>
> projectileDirection = -cannonModel.transform.zAxis
> projectileSpeed = 10
> gravityVector = vector(0,-9.81,0)
> initialPosition = vector(0,0,0)
> displacementPosition = initialPosition + (projectileDirection *
> projectileSpeed * time) + (0.5 * gravityVector * time * time)
>
> In your second equation, you're mixing scalar and vector values so you're
> probably not getting the results expected. SW3D will evaluate vector +
scalar
> by adding the scalar value to each member of the vector:
> vector(1,2,3) + 10 = vector(11,12,13)
>
> 1) no, that's the location of the model's pivot point (typically in
worldspace)
> 2) assuming that you have have the model created so that it's pivot is
aligned
> with -Z forward, just use the cannonModel.transform.-zAxis as the
directional
> vector, after you've finished rotating the cannon.
>

Greg Brant Guest