Posted: 17th Jun 2007 19:16
I have global coordinates to place a shield object next to a ship when it is hit. However, the ship is always moving and so I must glue the shield to the ship. The problem is, I don't know an easy way to obtain the local coordinates for placing the object after glueing. Is there a way to keep the object's position after glueing? There may be an easy answer to this that I have happened to miss.

Cheers Robin
Posted: 17th Jun 2007 19:40
I think it's the limb position / limb offset commands that could help you.
Posted: 17th Jun 2007 20:04
I think there would be a way of accomplishing this with those commands. However, it would be quite intensive. What I really need is a command to position an object which is glued using the global coordinates. I cannot use the local ones because the ship that the shield is being glued to could be at any angle.
Posted: 17th Jun 2007 22:39
The local coordinates are just the xyz offsets you used in the glue command...

Unless you mean getting global from local, in which case you use trig / the offsets / the source object's global position to do it.

In place of trig, you could use the newvalue commands.

All of this, or write your own glueing system, fairly simple, just set up an array to hold every glued object, with it's variable being it's parent. Then loop through them all, orienting them.

Eg;

+ Code Snippet
TYPE glue
   obj
   source
   x#,y#,z#
ENDTYPE

DIM gluedobject() AS glue

FUNCTION glueobject(sourceobj, glueobj, x#, y#, z#)
   ARRAY INSERT AT TOP gluedobject()
   ID = ARRAY COUNT(gluedobject(0))
   gluedobject(ID).source = sourceobj
   gluedobject(ID).obj = glueobj
   gluedobject(ID).x# = x#
   gluedobject(ID).y# = y#
   gluedobject(ID).z# = z#
ENDFUNCTION

FUNCTION handleglued()
   objects = ARRAY COUNT(gluedobject())
   FOR x = 1 TO objects
      obj = gluedobject(x).obj
      source = gluedobject(x).source
      POSITION OBJECT obj, OBJECT POSITION X(source), OBJECT POSITION Y(sourc), OBJECT POSITION Z(source)
      ROTATE OBJECT obj, OBJECT ANGLE X(source), OBJECT ANGLE Y(source), OBJECT ANGLE Z(source)
      MOVE OBJECT RIGHT obj, gluedobject(x).x#
      MOVE OBJECT UP obj, gluedobject(x).y#
      MOVE OBJECT obj, gluedobject(x).z#
   NEXT x
ENDFUNCTION
   


Call the type / array declaration before the main loop, call the glueobject function whenever you want (xyz are the xyz offsets), and call the handle function in the main loop. Then to get the global positions, just use the object position command for the glued object, and it'll return it's global position.

Local positions are again just the offsets.
Posted: 17th Jun 2007 23:39
The GLUE OBJECT system is flawed. Or very confusing, not sure which . I went with EzRotate and cured all my problems in one go.
Posted: 18th Jun 2007 17:17
Thanks for the posts people
I'll try out your suggestion Ruccus, cheers.
Posted: 18th Jun 2007 17:47
Is there a way to keep the object's position after glueing

Do you mean return it's position? Yes, it's pretty easy. They are global coordinates, but I don't see why that would matter. If you want local coordinates you'd just subract them from the parent object's coordinates.

x#=limb position x(obj,0)
y#=limb position y(obj,0)
z#=limb position z(obj,0)


Although you can no longer use the Object Position commands, you can find the position of Limb 0, which is the exact same.

If you want the new angles, use the Limb Direction commands.
Posted: 23rd Aug 2007 13:28
Did you ever figure this one out? I think your question has been misunderstood - I read it as wanting to convert global coordinates to local offsets relative to another object, so that you can glue an object without it's position suddenly changing.

Example: A ship, with any known position and rotation, encounters an asteroid with known global coordinates. You want to find the offsets, in relation to the ship, of the asteroid, so that when you use the glue object and offset limb commands, the asteroid stays in the same location but glued to the ship - right?

If this is what you want to do, you need to use the 3d vector commands. I did something very similar to this for creating a 3d radar in the last coding challenge - where I wanted to show objects in relation to the ship's orientation on the radar. If anyone's still interested, I will try and produce some example code for the code snippets area.
Posted: 23rd Aug 2007 14:02
You can use ezrotate
(or you could wait a little while for a plugin which MIGHT just HAPPEN to do all this and MIGHT be free and MIGHT be released very soon<hint>