THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/01/2011 at 20:28, xxxxxxxx wrote:
Well, I can show you the code I use to rotate my planet objects in PXG. It is using C++ but it might help you with Python.
//ROTATE PLANET
//====================================================//
Bool PlanetXObject::RotatePlanet(BaseObject *op, GeListNode* node){
if (!op) return FALSE;
BaseContainer *bc = ((BaseList2D* )node)->GetDataInstance();
if (!bc) return FALSE;
BaseDocument *doc = op->GetDocument();
if(!doc) return FALSE;
BaseTime time = doc->GetTime();
Real fps = doc->GetFps();
//Rotation Track Vector
DescID idRotX = DescID(DescLevel(ID_BASEOBJECT_REL_ROTATION,DTYPE_VECTOR,0),DescLevel(VECTOR_X,DTYPE_REAL,0));
//Planet COUNTER CLOCKWISE Rotation
//==========================================//
if (bc->GetBool(PLANETX_GENERAL_ENABLE_ROTATION) &&
bc->GetBool(PLANETX_GENERAL_ROTATION_DIRECTION) == PLANETX_GENERAL_ROTATION_COUNTER_CLOCKWISE){
//Remove Existing Track
//==========================================//
if (op->FindCTrack(idRotX)){
op->FindCTrack(idRotX)->Remove();
}
//Insert the New Track
//==========================================//
CTrack *track = op->FindCTrack(idRotX);
if (!track){
track = CTrack::Alloc(op,idRotX);
if (!track) return FALSE;
op->InsertTrackSorted(track);
}
//Get the Base Time
//==========================================//
BaseTime bstime = time;
//Set the Frame Rate (FPS)
//==========================================//
bstime.SetDenominator(fps);
Real deNomin;
deNomin = (60 *fps) / bc->GetReal(PLANETX_GENERAL_ROTATION_SPEED);
//First Key will be set at 0
//==========================================//
bstime.SetNumerator(0);
CKey *keyH = track->GetCurve()->AddKey(bstime,0);
if (!keyH) return false;
keyH->SetValue(track->GetCurve(),0); //Set Position to 0
//Second Key will be placed at deNomin
//==========================================//
bstime.SetNumerator(deNomin);
CKey *keyH2 = track->GetCurve()->AddKey(bstime,0);
if (!keyH2) return false;
keyH2->SetValue(track->GetCurve(),6.283185307); //Set Position to 360
track->SetAfter(CLOOP_REPEAT);
}
//Planet CLOCKWISE Rotation
//==========================================//
else if (bc->GetBool(PLANETX_GENERAL_ENABLE_ROTATION) &&
bc->GetBool(PLANETX_GENERAL_ROTATION_DIRECTION) == PLANETX_GENERAL_ROTATION_CLOCKWISE)
{
//Remove Existing Track
//==========================================//
if (op->FindCTrack(idRotX))
{
op->FindCTrack(idRotX)->Remove();
}
//Insert the New Track
//==========================================//
CTrack *track = op->FindCTrack(idRotX);
if (!track)
{
track = CTrack::Alloc(op,idRotX);
if (!track) return FALSE;
op->InsertTrackSorted(track);
}
//Get the Base Time
//==========================================//
BaseTime bstime = time;
//Set the Frame Rate (FPS)
//==========================================================================
bstime.SetDenominator(fps);
Real deNomin;
deNomin = (60 *fps) / bc->GetReal(PLANETX_GENERAL_ROTATION_SPEED);
//First Key will be set at 0
//==========================================================================
bstime.SetNumerator(0);
CKey *keyH = track->GetCurve()->AddKey(bstime,0);
if (!keyH) return false;
keyH->SetValue(track->GetCurve(),6.283185307); //Set Position to 360
//Second Key will be placed at 3 times the location of the frame rate
//(i.e. if FPS is set to 30, then the key will be placed at frame 45.
//==========================================================================
bstime.SetNumerator(deNomin);
CKey *keyH2 = track->GetCurve()->AddKey(bstime,0);
if (!keyH2) return false;
keyH2->SetValue(track->GetCurve(),0); //Set Position to 0
track->SetAfter(CLOOP_REPEAT);
}
else
{
//If the track exists remove it!
if (op->FindCTrack(idRotX))
{
op->FindCTrack(idRotX)->Remove();
}
}
return TRUE;
}
Hope that helps you. 