| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /*
- Copyright (C) 2011 by Ivan Safrin
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
- #pragma once
- #include "PolyGlobals.h"
- #include "PolyString.h"
- #include "PolyMatrix4.h"
- #include "PolyEntity.h"
- namespace Polycode {
- class Mesh;
- /**
- * Skeleton bone. Bones are bound to vertices of a mesh and when transformed, move the bound vertices of the mesh along with them. Bones are subclassed from Entity, but have their own hierarchy system.
- * @see Skeleton
- */
- class _PolyExport Bone : public Entity {
- public:
- /**
- * Constructor.
- * @param boneName Name of the bone.
- */
- explicit Bone(const String& boneName);
- virtual ~Bone();
-
- /**
- * Returns the name of the bone.
- * @return Name of the bone.
- */
- String getName() const;
- /**
- * Sets the parent bone of this bone.
- * @param bone New parent bone.
- */
- void setParentBone(Bone *bone);
-
- /**
- * Adds another bone as the child of this bone.
- * @param bone New parent bone.
- */
- void addChildBone(Bone *bone);
-
- /**
- * Returns the parent bone of this bone.
- * @return Parent bone of this bone.
- */
- Bone* getParentBone();
-
- /**
- * Returns the number of child bones of this bone.
- * @return Number of child bones.
- */
- int getNumChildBones();
-
- /**
- * Returns the child bone of this bone at the specified index.
- * @param index Index of the child bone to return.
- * @return Parent bone of this bone.
- */
- Bone *getChildBone(unsigned int index);
- /**
- * Returns the bone matrix
- * @return Bone matrix.
- */
- Matrix4 getBoneMatrix() const;
-
- /**
- * Sets the bone matrix.
- * @return Bone matrix.
- */
- void setBoneMatrix(const Matrix4& matrix);
-
- /**
- * Returns the rest matrix of this bone.
- * @return Rest matrix.
- */
- Matrix4 getRestMatrix() const;
-
- /**
- * Returns the full rest matrix of this bone.
- * @return Full rest matrix.
- */
- Matrix4 getFullRestMatrix() const;
-
- /**
- * Returns the rest matrix of this bone's parent.
- * @return Rest matrix of the bone's parent.
- */
- Matrix4 getParentRestMatrix() const;
-
- /**
- * @see getBoneMatrix()
- */
- Matrix4 getFinalMatrix() const;
-
- /**
- * Sets the rest matrix for this bone.
- * @param matrix New rest matrix.
- */
- void setRestMatrix(const Matrix4& matrix);
-
- /**
- * Sets the base matrix for this bone.
- * @param matrix New base matrix.
- */
- void setBaseMatrix(const Matrix4& matrix);
-
- /**
- * Returns the base matrix of this bone.
- * @return Base matrix.
- */
- const Matrix4& getBaseMatrix() const { return baseMatrix; }
-
- /**
- * Returns the full base matrix of this bone.
- * @return Full base matrix.
- */
- Matrix4 getFullBaseMatrix() const;
-
- void rebuildFinalMatrix();
- Matrix4 buildFinalMatrix() const;
-
-
- void intializeBone(const Vector3 &basePosition, const Vector3 &baseScale, const Quaternion &baseRotation, const Vector3 &restPosition, const Vector3 &restScale, const Quaternion &restRotation);
-
- /**
- * Id of the bone.
- */
- int parentBoneId;
- Matrix4 boneMatrix;
- Matrix4 restMatrix;
- Matrix4 baseMatrix;
- Matrix4 finalMatrix;
-
- Quaternion baseRotation;
- Vector3 baseScale;
- Vector3 basePosition;
-
- bool disableAnimation;
-
- protected:
- Bone* parentBone;
- std::vector<Bone*> childBones;
- String boneName;
- };
- }
|