THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/05/2012 at 14:10, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Windows ;
Language(s) : C++ ;
---------
This is very strange.
I have never used SetPoint() in C++. And I wanted to try it out.
So I converted a small python script into C++ that aligns a child's axis to the parent's axis. Without rotating the child object (A.K.A- it puts the points back where they were after the rotation).
But I get different results even though they are identical(AFAIK).
Python version:
import c4d
from c4d import utils
def main() :
obj = doc.GetActiveObject()
doc.StartUndo()
oldm = obj.GetMg()
points = obj.GetAllPoints()
pcount = obj.GetPointCount()
doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
obj.SetAbsRot(c4d.Vector(0))
obj.Message(c4d.MSG_UPDATE)
newm = obj.GetMg()
for i in xrange(pcount) :
obj.SetPoint(i,~newm*oldm*points[i]) #Set the points back where they were
obj.Message(c4d.MSG_UPDATE)
c4d.EventAdd()
doc.EndUndo()
if __name__=='__main__':
main()
C++ version :
BaseObject *obj = doc->GetActiveObject();
PointObject *pobj = ToPoint(obj); //Cast the BaseObject type to a PointObject type and assign it to a variable "pobj"
doc->StartUndo();
Matrix oldm = pobj->GetMg(); //Get and hold the matrix current state before we change it later
Vector *points = pobj->GetPointW(); //Get all the object's points before we rotate the object
LONG count = pobj->GetPointCount(); //Get the number of total points
doc->AddUndo(UNDOTYPE_CHANGE, pobj);
pobj->SetAbsRot(Vector(0)); //Rotate the object(also rotates the matrix)
pobj->Message(MSG_UPDATE);
Matrix newm = pobj->GetMg(); //Store the matrix new state values
AutoAlloc<Modeling> mod; //Create an instance of the Modeling class so we can use the SetPoint() function
mod->InitObject(pobj);
for(LONG i=0; i<count; i++)
{
mod->SetPoint(pobj, i, (!newm*oldm)*points[i], MODELING_SETPOINT_FLAG_EMPTY); //Set the points back where they were before pobj was rotated
}
pobj->Message(MSG_UPDATE); //Update the changes
The python version works as expected. But the C++ version rotates the object as well as the axis. In other words. The SetPoint() part of the C++ code where it's supposed to set the points back to where they originally were. Does not seem to be working properly. And I'm stumped why this isn't working.
I know I'm missing something stupid. But I can't see it.
What am I doing wrong?
-ScottA