home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-27 | 3.3 KB | 145 lines | [TEXT/CWIE] |
- //
- // CProp.cp
- //
- // class CProp
- // Class for manipulating a QD3D object that may be
- // spun and tossed independently.
- //
- // by James Jennings
- // Started November 23, 1995
- //
-
- #include "CProp.h"
- #include "CBoxMaker.h"
- #include "CClubMaker.h"
- #include "QD3D Debug Macros.h"
- #include "StQ3Disposer.h"
-
- //
- // class CProp
- //
- CProp::CProp()
- : mModel(0), mThing(0), mTranslation(0), mSpin(0), mTilt(0)
- {
- // Does nothing: Be sure to call MakeModel after construction.
- }
-
- CProp::CProp(const CProp & prop)
- : mModel(0), mThing(0), mTranslation(0), mSpin(0), mTilt(0)
- {
- SignalPStr_("\pHaven't written CProp copy constructor yet.");
- }
- // CProp::CProp(const TQ3FileObject & source);
- CProp::~CProp()
- {
- Dispose();
- }
-
- void
- CProp::Dispose()
- { // Safely dispose of everything.
- if (mModel)
- ::Q3Object_Dispose(mModel);
- mModel = 0;
- if (mThing)
- ::Q3Object_Dispose(mThing);
- mThing = 0;
- if (mTranslation)
- ::Q3Object_Dispose(mTranslation);
- mTranslation = 0;
- if (mSpin)
- ::Q3Object_Dispose(mSpin);
- mSpin = 0;
- if (mTilt)
- ::Q3Object_Dispose(mTilt);
- mTilt = 0;
- }
-
- void
- CProp::SetPosition(TQ3Point3D &where)
- { // Set the position of the prop.
- // Note: TQ3Point3D and TQ3Vector3D have the same "structure" and can be cast.
- TQ3Status status = ::Q3TranslateTransform_Set(mTranslation,(TQ3Vector3D*) &where);
- ThrowIfQ3Fail_(status);
- }
-
- void
- CProp::SetSpinAngle(float theta)
- {
- TQ3Status status = ::Q3RotateAboutPointTransform_SetAngle(mSpin, theta);
- ThrowIfQ3Fail_(status);
- }
-
- void
- CProp::SetTiltAngle(float theta)
- {
- TQ3Status status = ::Q3RotateAboutPointTransform_SetAngle(mTilt, theta);
- ThrowIfQ3Fail_(status);
- }
-
- void
- CProp::MakeModel(CObjectMaker<TQ3GeometryObject> &aThing, TQ3Point3D &anOrigin)
- {
- try {
- // create the transforms
- TQ3Vector3D moveOrigin;
- ::Q3Vector3D_Set(&moveOrigin, -anOrigin.x, -anOrigin.y, -anOrigin.z );
- TQ3TransformObject origin = ::Q3TranslateTransform_New(&moveOrigin);
- ThrowIfNil_(origin);
- StQ3Disposer ori(origin);
-
- TQ3Vector3D translate = {0,0,0};
- mTranslation = ::Q3TranslateTransform_New(&translate);
- ThrowIfNil_(mTranslation);
-
- TQ3Point3D center = {0,0,0};
- TQ3RotateAboutPointTransformData spin;
- spin.axis = kQ3AxisX;
- spin.radians = 0.0;
- spin.about = center;
- mSpin = ::Q3RotateAboutPointTransform_New(&spin);
- ThrowIfNil_(mSpin);
-
- spin.axis = kQ3AxisZ;
- mTilt = ::Q3RotateAboutPointTransform_New(&spin);
- ThrowIfNil_(mTilt);
-
- // Define a shading type for the group
- TQ3ShaderObject illuminationShader;
- illuminationShader = ::Q3PhongIllumination_New();
- StQ3Disposer ill(illuminationShader);
-
- MakeThing(aThing);
-
- // Make a group to put it all in
- mModel = ::Q3DisplayGroup_New();
- ThrowIfNil_(mModel);
-
- TQ3GroupPosition pos;
- pos = ::Q3Group_AddObject(mModel, illuminationShader);
- ThrowIf_(pos==0);
- // Note the order of the transforms. The mThing is last.
- pos = ::Q3Group_AddObject(mModel, mTranslation);
- ThrowIf_(pos==0);
- pos = ::Q3Group_AddObject(mModel, mTilt);
- ThrowIf_(pos==0);
- pos = ::Q3Group_AddObject(mModel, mSpin);
- ThrowIf_(pos==0);
- pos = ::Q3Group_AddObject(mModel, origin); // center it
- ThrowIf_(pos==0);
- pos = ::Q3Group_AddObject(mModel, mThing); // the prop
- ThrowIf_(pos==0);
- }
- catch (...) {
- Dispose();
- throw;
- }
- }
-
- void
- CProp::MakeThing(CObjectMaker<TQ3GeometryObject> &aThing)
- {
- mThing = ::Q3Shared_GetReference(aThing.Get());
- ThrowIfNil_(mThing);
- }
-