i am sure this is very basic transforming stuff, but i am afraid i am still struggling with Vectors, Quaternion, Rotation and all that.

So, i have this spaceship which fires weapons and those weapons have different lengths.

Both the spaceship and weapon are physic Nodes.

When a weapon is fired, i want to place the created projectile infront of the spaceship, so that they do not touch.

In my projectile Constructor i have the following variables:

public MissileProjectile(final PhysicsSpace physics,
final Vector3f direction, // direction the Spaceship is looking (rotationColumn(2))
final Vector3f startLocation, // location of the weapon mounted on the Ship in WorldCoordiantes
final Quaternion rotation) { // current rotation of the spaceship
TriMesh model = new Cylinder("dummy missile model", 5, 5, 0.05f, 1.5f); // dummy model
updateModel(model); // (updates boundingboxes and physicsNode)
}

Right now, half of the missile is inside the spaceship BoundingBox of course.
How can i add the zExtent from the missile to the startLocation in the direction the Spaceship is currently facing?

spaceship.getlocalrotation() will give the direction of the node of the spaceship.

if u do have a model loaded to it, get the model spatial first then call getlocalrotation().

the method returns a quaternion(x,y,z,w) which defines the facing direction. then u take the x, y, z to form a vector3f and multiply this vector by the length of ur space ship. the result vector is the position of the head of ur spaceship. then u can figure out the rest depends on where ur wanna place the missle.

but becareful all the vectors u get r in local coordinate system.

If i multiply the rotation and add it to the startLocation, the Missile gets created behind and left or right of the Ship (depends on rotation).

When i create the Missile, i do already know the exact startingLocation, the Front of my SpaceShip's BoundingBox. This startlocation is in World coordinates.

What i also know, is the Rotation of the SpaceShip, and with that, the direction its heading.

if you have an initial heading (say looking up the z axis x0 y0 z1) then multiply this by the quaternion returned from getLocalRotation…

this will give you the new heading as a unit vector…

e.g.

Hinital = 0 0 1

Rotation = 90 degrees about Y

newH = Rotation * Hinitial = 1 0 0

if your ship has a bounding radius of 10 and the projectile has a bounding radius of 5 then add the two together to get a magnitude for the displacement

rOffset = rship * rprojectile = 5 + 10 = 15

now scale the modified heading vector

displacement = newH * rOffset = 15 0 0

and if the ship is located at 20 0 50 then the missle location is