Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Rotating a 3D object to match another

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Nov 2019 03:24 Edited at: 28th Nov 2019 03:24
I have two 3D objects, gizmo1.obj and gizmo2.obj. They are the same shape (In fact they are the same except gizmo2.obj has been turned around it's axis).
The vertex line up so vertex 1 in gizmo1.obj = vertex 1 in gizmo2.obj and so on.
How do i get the rotation values x/y/z in order to rotate gizmo1.obj to the same rotation as gizmo2.obj?



Thanks in advance for any help

Attachments

Login to view attachments
theblackbones
5
Years of Service
User Offline
Joined: 31st Jan 2019
Location: France
Posted: 28th Nov 2019 14:59
Hello Blink0k,
What do you mean, an AlignVectorObject1ToVectorObject2 Function with Lerp ?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Nov 2019 21:18
I want to the the rotation values X,Y,Z that will make the shape on the right. Look exactly like the shape on the left
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 28th Nov 2019 21:25 Edited at: 28th Nov 2019 21:32
Interesting...so the rotation is done in the .obj file and you want both objects to line up.
Now I wonder, If you can be certain both are the same, why not just copy and replace the wrong object.
Another way you could take, is you select a face of object A and one of object B then you align the face of object A so the normal and the height for example fits object B...from there youll need to adjust the other vertices.
The rest is just some math because you know the difference of the selected faces normals and positions...

[Edit]Better select the Vertex not the face and get the orientation using the other two vertices which make up one triangle.
Well if you make it look like you selected a face in the editor is up to you I guess[Edit]
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Nov 2019 21:35
Here is the situation.
1. I am writing an app that will take a scene created in blender (or any other 3d app) and split out all the models remembering their position and allowing the user to add attributes to each model (physics etc)
2. One option is to specify that a model is a "clone" of another model (It's up to the user to ensure that they are in fact the same model). It may be a clone but the user has rotated it to fit into their scene
3. So i need to figure out the rotation values so i can clone the original object and then rotate it to it's intended orientation.

Quote: "Another way you could take, is you select a face of object A and one of object B then you align the face of object A so the normal and the height for example fits object B...from there youll need to adjust the other vertices."

I'm trying a version of this right now only with edges.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 28th Nov 2019 22:47
Quote: "I'm trying a version of this right now only with edges."

You'll want 3 points or you dont get the full orientation

I'd probably position the other vertices using this calculation:
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Nov 2019 22:59
Quote: "You'll want 3 points or you don't get the full orientation"

Yes. I'll use one edge at a time

Quote: "I'd probably position the other vertices using this calculation:"

You can't just position vertices arbitrarily. you need to rotate the entire model
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Nov 2019 23:20 Edited at: 28th Nov 2019 23:21
I think if you know 3 of the vertices of the original object and the same 3 from the rotated janbos equations
may work

On a diff note just like to say its good that your revisiting your project
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 29th Nov 2019 13:48 Edited at: 29th Nov 2019 15:45
Quote: "You can't just position vertices arbitrarily. you need to rotate the entire model"

If I understand it right, you want to go through all vertices and give them a new position (so like it is rotated).
Youll need the offsets of each vertex and the angle difference of the two selected triangles then execute the calculation on each vertex using your gathered informations.
You want to change the mesh, right ? or just rotate the object so it has the same orientation ?

Just rotating the entire model using the "face orientation" is much easier
Claculating the two Angles from your Normal Vector should be something like this:

You could also do everything with vectors but using angles in AppGameKit is more straight Forward I think.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Nov 2019 21:06
Quote: "You want to change the mesh, right ? or just rotate the object so it has the same orientation ?."

i want to rotate the object so it has the same orientation
You code is helpful

Login to post a reply

Server time is: 2024-04-26 12:03:31
Your offset time is: 2024-04-26 12:03:31