www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: neo187 on September 16, 2011, 05:35:10 pm

Title: Help creating a Lerp function (absolute positions)
Post by: neo187 on September 16, 2011, 05:35:10 pm
I am trying to create a Lerp function like the one in Unity whereby by giving two absolute positions and a time interval the function would interpolate between the two at each call....

From playing around with the Object3D.translate function I seem to understand that it translates the object by a given vector....is there an equivalent to position the object in an absolute position in space? Say (10, 0, 20).

Also, if I want to make the object face the target position, would I be using the setOrientation method and give it the vector of the target position?

Thank you very much!

Title: Re: Help creating a Lerp function (absolute positions)
Post by: EgonOlsen on September 16, 2011, 07:59:20 pm
You can apply an absolute translation by doing

Code: [Select]
obj.clearTranslation();
obj.translate(....);

You can use setOrientation() as long as you have a proper up vector too. The direction vector has to be the difference vector between the objects position and the target, not the target vector itself.
Title: Re: Help creating a Lerp function (absolute positions)
Post by: neo187 on September 16, 2011, 08:33:43 pm
That did the trick. Thank you very much!

Would you have any tips on how to best position objects in 3D space programmatically? I'm really only used to have a visual editor to drag and drop things with.... Say I build my scene in Blender, is there a way to calculate a position in jpct world space knowing its position in the Blender scene?

Thank you very much for your help!
Title: Re: Help creating a Lerp function (absolute positions)
Post by: Marlon on December 24, 2011, 02:51:13 am
I am using
Code: [Select]
obj.clearTranslation();
obj.translate(....);
as well and the object gets placed correctly.

But there seem to be a problem with child objects. If our object gets a child (obj.addChild(child)) the child isn't linked correctly with its parent.
Is there a way to solve this problem when doing absolute position?
Title: Re: Help creating a Lerp function (absolute positions)
Post by: EgonOlsen on December 25, 2011, 11:36:11 am
I am using
Code: [Select]
obj.clearTranslation();
obj.translate(....);
as well and the object gets placed correctly.

But there seem to be a problem with child objects. If our object gets a child (obj.addChild(child)) the child isn't linked correctly with its parent.
Is there a way to solve this problem when doing absolute position?
I don't see how this should be related. It works with normal, relative translations but a call to clearTranslation() kill is? Makes no sense to me...it's just another operation on the same internal matrix...do you have a test case that shows this problem?
Title: Re: Help creating a Lerp function (absolute positions)
Post by: Marlon on December 25, 2011, 09:29:16 pm
If I add a child to an object, the child gets moved with the object (relative movement). So in my test program its actually well placed and I never saw a problem with it.
At my main project I use absolute object placement like described in this thread. For the main object there isn't a problem but for all child objects there is. Those objects don't get placed correctly, they are moving in a strange way (absolute placement doesn't seem to work here).

I just fixed this problem, while overwriting the method addChild(Object3D). I just created an own list for all child objects and the behaviour of the parent object is delegated to all childs. So all is fine here now:)

But if you want me to put a sample code with the problem here, just tell me and I will do.
Title: Re: Help creating a Lerp function (absolute positions)
Post by: EgonOlsen on December 26, 2011, 08:35:33 pm
Maybe this is based on a misunderstanding. The absolute position is absolute only relative to an objects parents. I.e. if you translate the parent by (10,0,0) and give a child an "absolute" translation of (11,0,0), the result won't be a child located one unit right of the parent but a child located at (21,0,0).