Jump to content

attachElementToElement (trig help please)


Recommended Posts

Wiki Page

Right the offset values are in X,Y and Z. I can get the offset values (relative to the parent object) by playing around with the trig functions, but that takes some time and I have yet to find a rule of thumb for it, Can someone give me a quick rundown on each (cos, sin, -cos, -sin) and explain how you would use them to position an object around another object/element.

Thanks in advance (I lack the sideways thinking to work it out)

Link to comment

AttachElementToElement's offset arguments are relative. This means if you want to attach an element to an element, imagine that the parent element's rotation is 0. For attaching at x -2 would attach behind the element, no matter what it's current rotation.

As far as calculating this for two real world positions - it gets a little more complicated. Trigonometry only allows for taking into account two axes. This is fine if, for example, the Z offset is always 0. If you want to calculate a relative argument on all 3 axes, you'll have to use quatornion math or matrices.

Link to comment

Well according to that you want to know how to place a object around a object cosinus and sinus are no good choice. They always require at least two given sides and regarding to your request its basically not the right form? If you are trying to place a object like:

:: object ::

:: object :: :: object ::

:: object ::

Then its a perfect choice to use sinus and cosinus, but if i got you right you want to basically do this:

:: b i g O

::smallobject:: b

:: t c e j

Right?

If not, could you at least draw a example or anything? it would help.

Link to comment

Well, all i can see from your picture is that the object should be on a different position and i am not sure how you want to calculate that? Why not getting the position of the first object and adjusting these, then creating the next one? Sorry but i dont get your image either lol.

Link to comment

You can use just trig to calculate x-y positions and then just set z, can't you?

OB would be the distance and the corner would be the degrees you want. If you attach to player, I think they are relative values so the player faces upwards in y direction. (Like being in 0,0,0, rotation 0).

And there you have a nice triangle.

[attachment=0]trig.png[/attachment]

x_offs = math.sin(math.rad(corner)) * OB 
y_offs = math.cos(math.rad(corner)) * OB  
z_offs = somerandomnumber 
attachElement(theElement, theAttachToElement, x_offs, y_offs, z_offs, x_rot_offs, y_rot_offs, z_rot_offs) 

That isn't so hard ;)

Note however that math.sin and math.cos operate in radians iirc so you have to convert them before using (with math.rad)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...