#include #include "AFramework.h" #include "AGLObjects.h" #include "AnimationToolkit.h" class AButterfly : public AFramework { public: AButterfly() : AFramework(AFramework::Perspective) { } void setup() { AJoint* body = new AJoint("Body"); body->setLocalTranslation(AVector3(1,2,1)*100); body->setLocalRotation(AQuaternion(AVector3(0,1,0), 45 * ADeg2Rad)); skeleton.addJoint(body); AJoint* lwing = new AJoint("LWing"); lwing->setLocalTranslation(AVector3(0.1,0,0)*100); skeleton.addJoint(lwing); AJoint* rwing = new AJoint("RWing"); rwing->setLocalTranslation(AVector3(-0.1,0,0)*100); skeleton.addJoint(rwing); } void draw() { // Example: Compute global transforms to draw // NOTE: We normally call ASkeleton::fk() to compute global transforms! AJoint* body = skeleton.getByName("Body"); ATransform bodyLocal = body->getLocal2Parent(); ATransform bodyGlobal = bodyLocal; // because body is the root // Draw body AVector3 e1Local(0,0,100); AVector3 e2Local(0,0,-100); AVector3 e1Global = bodyGlobal.transformPoint(e1Local); AVector3 e2Global = bodyGlobal.transformPoint(e2Local); ASetMaterial(AVector3(0.5,0,1)); ADrawLimb(e1Global, e2Global, 5); // Draw body coordinate axes AVector3 fwdLocal(0,0,1); AVector3 upLocal(0,1,0); AVector3 leftLocal(1,0,0); AVector3 pGlobal = bodyGlobal.transformPoint(AVector3(0,0,0)); AVector3 fwdGlobal = bodyGlobal.transformVector(fwdLocal); AVector3 upGlobal = bodyGlobal.transformVector(upLocal); AVector3 leftGlobal = bodyGlobal.transformVector(leftLocal); ASetMaterial(AVector3(0,0,1)); ADrawLimb(pGlobal, pGlobal + fwdGlobal * 150, 2); ASetMaterial(AVector3(0,1,0)); ADrawLimb(pGlobal, pGlobal + upGlobal * 150, 2); ASetMaterial(AVector3(1,0,0)); ADrawLimb(pGlobal, pGlobal + leftGlobal * 150, 2); // Draw wings AJoint* lwing = skeleton.getByName("LWing"); ATransform lwingGlobal = bodyGlobal * lwing->getLocal2Parent(); ASetMaterial(AVector3(1,0,0)); // Red for left ADrawLimb(lwingGlobal.translation, bodyGlobal.translation, 10); AJoint* rwing = skeleton.getByName("RWing"); ATransform rwingGlobal = bodyGlobal * rwing->getLocal2Parent(); ASetMaterial(AVector3(1,1,0)); // Yellow for right ADrawLimb(rwingGlobal.translation, bodyGlobal.translation, 10); } private: ASkeleton skeleton; }; int main(int argc, char** argv) { AButterfly viewer; viewer.init(argc, argv); viewer.run(); }