Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ivansafrin/Polycode
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansafrin committed Apr 20, 2015
2 parents 0def373 + 956f3f2 commit bc46891
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Core/Contents/Include/PolyBone.h
Expand Up @@ -141,6 +141,9 @@ namespace Polycode {

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.
Expand Down
8 changes: 6 additions & 2 deletions Core/Contents/Include/PolySkeleton.h
Expand Up @@ -219,9 +219,13 @@ namespace Polycode {
* Returns a bone at the specified index.
* @param index Bone index.
*/
Bone *getBone(int index) const;

Bone *getBone(unsigned int index) const;

void addBone(Bone *bone);
void removeBone(Bone *bone);

unsigned int getBoneIndexByBone(Bone *bone);

protected:

Entity *bonesEntity;
Expand Down
28 changes: 28 additions & 0 deletions Core/Contents/Source/PolyBone.cpp
Expand Up @@ -71,6 +71,34 @@ Matrix4 Bone::getBoneMatrix() const {
}
}

void Bone::intializeBone(const Vector3 &basePosition, const Vector3 &baseScale, const Quaternion &baseRotation, const Vector3 &restPosition, const Vector3 &restScale, const Quaternion &restRotation) {

this->baseRotation = baseRotation;
this->baseScale = baseScale;
this->basePosition = basePosition;

setPosition(basePosition);
setRotationByQuaternion(baseRotation);
setScale(baseScale);
rebuildTransformMatrix();

setBaseMatrix(getTransformMatrix());
setBoneMatrix(getTransformMatrix());

Matrix4 restRotationMatrix = restRotation.createMatrix();

Matrix4 restPositionMatrix;
restPositionMatrix.identity();
restPositionMatrix.setPosition(restPosition.x, restPosition.y, restPosition.z);

Matrix4 restScaleMatrix;
restScaleMatrix.identity();
restScaleMatrix.setScale(restScale);


setRestMatrix(restScaleMatrix*restRotationMatrix*restPositionMatrix);
}

Matrix4 Bone::getFinalMatrix() const {
return finalMatrix;
}
Expand Down
18 changes: 14 additions & 4 deletions Core/Contents/Source/PolyGLRenderer.cpp
Expand Up @@ -699,8 +699,13 @@ void OpenGLRenderer::createRenderTextures(Texture **colorBuffer, Texture **depth
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferID);
glGenTextures(1,&colorTexture);
glBindTexture(GL_TEXTURE_2D,colorTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(textureFilteringMode == TEX_FILTERING_NEAREST) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Expand Down Expand Up @@ -729,8 +734,13 @@ void OpenGLRenderer::createRenderTextures(Texture **colorBuffer, Texture **depth
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferID);
glGenTextures(1,&depthTexture);
glBindTexture(GL_TEXTURE_2D,depthTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if(textureFilteringMode == TEX_FILTERING_NEAREST) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

Expand Down
17 changes: 9 additions & 8 deletions Core/Contents/Source/PolySceneMesh.cpp
Expand Up @@ -272,16 +272,17 @@ void SceneMesh::renderMeshLocally() {
if(boneWeight > 0.0) {

Bone *bone = skeleton->getBone(mesh->vertexBoneIndexArray.data[(i*4)+b]);
if(bone) {
Vector3 restVert(mesh->vertexPositionArray.data[i*3], mesh->vertexPositionArray.data[(i*3)+1], mesh->vertexPositionArray.data[(i*3)+2]);

Vector3 restVert(mesh->vertexPositionArray.data[i*3], mesh->vertexPositionArray.data[(i*3)+1], mesh->vertexPositionArray.data[(i*3)+2]);

tPos += bone->finalMatrix * restVert * (boneWeight);
tPos += bone->finalMatrix * restVert * (boneWeight);
Vector3 nvec(mesh->vertexNormalArray.data[i*3], mesh->vertexNormalArray.data[(i*3)+1], mesh->vertexNormalArray.data[(i*3)+2]);

Vector3 nvec(mesh->vertexNormalArray.data[i*3], mesh->vertexNormalArray.data[(i*3)+1], mesh->vertexNormalArray.data[(i*3)+2]);

nvec = bone->finalMatrix.rotateVector(nvec);

norm += nvec * (boneWeight);
nvec = bone->finalMatrix.rotateVector(nvec);

norm += nvec * (boneWeight);
}
}
}

Expand Down
38 changes: 33 additions & 5 deletions Core/Contents/Source/PolySkeleton.cpp
Expand Up @@ -38,10 +38,17 @@ Skeleton *Skeleton::BlankSkeleton() {

Skeleton::Skeleton(const String& fileName) : Entity() {
baseAnimation = NULL;
bonesEntity = new Entity();
bonesEntity->visible = false;
addChild(bonesEntity);
loadSkeleton(fileName);
}

Skeleton::Skeleton() {
baseAnimation = NULL;
bonesEntity = new Entity();
bonesEntity->visible = false;
addChild(bonesEntity);
}

Skeleton::~Skeleton() {
Expand All @@ -59,7 +66,10 @@ Bone *Skeleton::getBoneByName(const String& name) const {
return NULL;
}

Bone *Skeleton::getBone(int index) const {
Bone *Skeleton::getBone(unsigned int index) const {
if(index >= bones.size()) {
return NULL;
}
return bones[index];
}

Expand Down Expand Up @@ -143,16 +153,34 @@ void Skeleton::Update() {
}
}

void Skeleton::addBone(Bone *bone) {
bones.push_back(bone);
}

void Skeleton::removeBone(Bone *bone) {
for(int i=0; i < bones.size(); i++) {
if(bones[i] == bone) {
bones.erase(bones.begin()+i);
return;
}
}
}

unsigned int Skeleton::getBoneIndexByBone(Bone *bone) {
for(int i=0; i < bones.size(); i++) {
if(bones[i] == bone) {
return i;
}
}
return 0;
}

void Skeleton::loadSkeleton(const String& fileName) {
OSFILE *inFile = OSBasics::open(fileName.c_str(), "rb");
if(!inFile) {
return;
}

bonesEntity = new Entity();
bonesEntity->visible = false;
addChild(bonesEntity);

unsigned int numBones;
float t[3],rq[4],s[3];

Expand Down
Expand Up @@ -7,62 +7,62 @@
<key>2DPhysics_Basic.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>11</integer>
<integer>12</integer>
</dict>
<key>2DPhysics_CollisionOnly.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>14</integer>
<integer>15</integer>
</dict>
<key>2DPhysics_Contacts.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>12</integer>
<integer>13</integer>
</dict>
<key>2DPhysics_Joints.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>13</integer>
<integer>14</integer>
</dict>
<key>2DPhysics_PointCollision.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>15</integer>
<integer>16</integer>
</dict>
<key>3DBasics.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>8</integer>
</dict>
<key>3DPhysics_Basic.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>18</integer>
<integer>19</integer>
</dict>
<key>3DPhysics_Character.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>20</integer>
<integer>21</integer>
</dict>
<key>3DPhysics_CollisionOnly.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>16</integer>
<integer>17</integer>
</dict>
<key>3DPhysics_Contacts.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>19</integer>
<integer>20</integer>
</dict>
<key>3DPhysics_RayTest.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>17</integer>
<integer>18</integer>
</dict>
<key>3DPhysics_Vehicle.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>21</integer>
<integer>22</integer>
</dict>
<key>BasicImage.xcscheme</key>
<dict>
Expand All @@ -87,7 +87,7 @@
<key>MaterialsAndLights.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>9</integer>
</dict>
<key>MouseInput.xcscheme</key>
<dict>
Expand All @@ -97,12 +97,12 @@
<key>ParticleSystems.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>16</integer>
<integer>7</integer>
</dict>
<key>PlayingSounds.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>10</integer>
<integer>11</integer>
</dict>
<key>PositionalSounds.xcscheme</key>
<dict>
Expand All @@ -122,7 +122,7 @@
<key>SkeletalAnimation.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>9</integer>
<integer>10</integer>
</dict>
<key>Transforms.xcscheme</key>
<dict>
Expand Down
Expand Up @@ -47,7 +47,11 @@ PhysicsScene2DEntity::PhysicsScene2DEntity(Entity *entity, b2World *world, Numbe
// Create body definition---------------------------------------
b2BodyDef bodyDef;
bodyDef.position.Set(compoundMatrix.getPosition().x/worldScale, compoundMatrix.getPosition().y/worldScale);
bodyDef.angle = entity->getRoll()*(PI/180.0f);

Number ax,ay,az;
compoundMatrix.getEulerAngles(&ax, &ay, &az);

bodyDef.angle = az*(PI/180.0f);
bodyDef.bullet = isSensor;
bodyDef.fixedRotation = fixedRotation;
if(isStatic)
Expand Down

0 comments on commit bc46891

Please sign in to comment.