11th September 2007, 11:08 PM | #1 |
Member
Advanced member
Join Date: May 2006
Posts: 36
|
How to move an object to the origin and back
Hello. I would like to know how to move an object to the origin and then back to its original location. I've tried the code that is below; however, when the function exits, the object is left at the origin.
Code:
ACObject *obj = ... get from somewhere // get the center of the object Point3 *centre = ac_object_get_centre(obj); // move it to the origin translate_object_zero(obj); // do something useful here // move it back translate_object(obj,centre); Anyone know what I'm doing wrong? Using AC3D 6.2.05 linux version. |
11th September 2007, 11:39 PM | #2 |
Senior Member
Professional user
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
|
Re: How to move an object to the origin and back
What happens if you de-reference the pointer to the object center?
i.e. Point3 ptCentre = *(ac_object_get_centre(obj)); translate_object_zero(obj); translate_object(obj, &ptCentre); |
12th September 2007, 09:04 PM | #3 |
Member
Advanced member
Join Date: May 2006
Posts: 36
|
Re: How to move an object to the origin and back
That worked! So why does it work?
Thanks for your help! |
12th September 2007, 10:46 PM | #4 |
Senior Member
Professional user
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
|
Re: How to move an object to the origin and back
When you get the pointer to the center, you're storing the address of the memory where the data is located, not the data itself. When AC3D moves the object, then center moves too, of course. If you're looking the center up through the pointer, you'll get the *new* location of the center because the data at that address has changed--which isn't what you want.
By de-referencing, you cause your code to store a *copy* of the center location, meaning the number won't change no matter how much you move the object. |
|
|