Go Back   AC3D Forums > Technical > AC3D Developers
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 11th September 2007, 11:08 PM   #1
conzar
Member
Advanced member
 
conzar's Avatar
 
Join Date: May 2006
Posts: 36
Question 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);
I've also tried translate_object_abs and get the same results.

Anyone know what I'm doing wrong?

Using AC3D 6.2.05 linux version.
conzar is offline   Reply With Quote
Old 11th September 2007, 11:39 PM   #2
lisa
Senior Member
Professional user
 
lisa's Avatar
 
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
Default 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);
lisa is offline   Reply With Quote
Old 12th September 2007, 09:04 PM   #3
conzar
Member
Advanced member
 
conzar's Avatar
 
Join Date: May 2006
Posts: 36
Default Re: How to move an object to the origin and back

That worked! So why does it work?

Thanks for your help!
conzar is offline   Reply With Quote
Old 12th September 2007, 10:46 PM   #4
lisa
Senior Member
Professional user
 
lisa's Avatar
 
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
Default 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.
lisa is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 01:49 PM.


AC3D Forum
(C) Inivis Limited 2020