Ejemplo n.º 1
0
static void dlUpdateMatrix( dlObject *object )
{
   kmMat4 translation,
          rotation,
          scale,
          temp;

   CALL("%p", object);

   /* translation */
   kmMat4Translation( &translation,
                      object->translation.x,
                      object->translation.y,
                      object->translation.z  );

   /* rotation */
   kmMat4RotationX( &rotation, kmDegreesToRadians(object->rotation.x) );
   kmMat4Multiply(  &rotation, &rotation,
                    kmMat4RotationY( &temp, kmDegreesToRadians(object->rotation.y) ) );
   kmMat4Multiply(  &rotation, &rotation,
                    kmMat4RotationZ( &temp, kmDegreesToRadians(object->rotation.z) ) );

   /* scale */
   kmMat4Scaling( &scale,
                  object->scale.x,
                  object->scale.y,
                  object->scale.z  );

   /* build matrix */
   kmMat4Multiply( &translation, &translation, &rotation );
   kmMat4Multiply( &object->matrix, &translation, &scale );
   object->transform_changed = 0;
}
Ejemplo n.º 2
0
void Transform::flush()
{
    if (m_needFlush)
    {
        m_needFlush=false;
        kmMat4Identity(&m_matrix);
        kmMat4 t_mat;
        
        //position
        kmMat4Identity(&t_mat);
        kmMat4Translation(&t_mat,m_x,m_y,0);
        kmMat4Multiply(&m_matrix, &m_matrix, &t_mat);
        
        //rotation
        kmMat4Identity(&t_mat);
        kmMat4RotationZ(&t_mat, m_rotationZ*PI/180.0f);
        kmMat4Multiply(&m_matrix, &m_matrix, &t_mat);
        
        //scale
        kmMat4Identity(&t_mat);
        kmMat4Scaling(&t_mat, m_scaleX, m_scaleY, 1);
        kmMat4Multiply(&m_matrix, &m_matrix, &t_mat);
        
        //anchorPoint
        kmMat4Identity(&t_mat);
        kmMat4Translation(&t_mat,(-m_anchorX*m_width),(-m_anchorY*m_height),0);
        kmMat4Multiply(&m_matrix, &m_matrix, &t_mat);
        
    }
}
Ejemplo n.º 3
0
void kmGLScalef(float x, float y, float z)
{
    km_mat4_stack_context *current_context = (km_mat4_stack_context *)pthread_getspecific(current_context_key);

	kmMat4 scaling;
	kmMat4Scaling(&scaling, x, y, z);
	kmMat4Multiply(current_context->current_stack->top, current_context->current_stack->top, &scaling);
}
Ejemplo n.º 4
0
/* \brief transform V3B object */
static void _glhckSkinBoneTransformObjectV3B(glhckObject *object)
{
   unsigned int i, w;
   kmMat4 bias, biasinv, scale, scaleinv;
   static glhckVector3b zero = {0,0,0};

   kmMat4Translation(&bias, object->geometry->bias.x, object->geometry->bias.y, object->geometry->bias.z);
   kmMat4Scaling(&scale, object->geometry->scale.x, object->geometry->scale.y, object->geometry->scale.z);
   kmMat4Inverse(&biasinv, &bias);
   kmMat4Inverse(&scaleinv, &scale);

   for (i = 0; i != object->numSkinBones; ++i) {
      glhckSkinBone *skinBone = object->skinBones[i];
      for (w = 0; w != skinBone->numWeights; ++w) {
         glhckVertexWeight *weight = &skinBone->weights[w];

         if (weight->vertexIndex >= (glhckIndexi)object->geometry->vertexCount)
            continue;

         memcpy(&object->geometry->vertices.v3b[weight->vertexIndex].vertex, &zero, sizeof(glhckVector3s));
         memcpy(&object->geometry->vertices.v3b[weight->vertexIndex].normal, &zero, sizeof(glhckVector3s));
      }
   }

   for (i = 0; i != object->numSkinBones; ++i) {
      kmMat3 transformedNormal;
      kmMat4 transformedVertex, transformedMatrix, offsetMatrix;
      glhckSkinBone *skinBone = object->skinBones[i];
      if (!skinBone->bone) continue;

      kmMat4Multiply(&transformedMatrix, &biasinv, &skinBone->bone->transformedMatrix);
      kmMat4Multiply(&transformedMatrix, &scaleinv, &transformedMatrix);
      kmMat4Multiply(&offsetMatrix, &skinBone->offsetMatrix, &bias);
      kmMat4Multiply(&offsetMatrix, &offsetMatrix, &scale);
      kmMat4Multiply(&transformedVertex, &transformedMatrix, &offsetMatrix);
      kmMat3AssignMat4(&transformedNormal, &transformedVertex);

      for (w = 0; w != skinBone->numWeights; ++w) {
         glhckVector3f bindVertex, bindNormal;
         glhckVertexWeight *weight = &skinBone->weights[w];

         if (weight->vertexIndex >= (glhckIndexi)object->geometry->vertexCount)
            continue;

         glhckSetV3(&bindVertex, &object->bindGeometry->vertices.v3b[weight->vertexIndex].vertex);
         glhckSetV3(&bindNormal, &object->bindGeometry->vertices.v3b[weight->vertexIndex].normal);
         kmVec3MultiplyMat4((kmVec3*)&bindVertex, (kmVec3*)&bindVertex, &transformedVertex);
         kmVec3MultiplyMat3((kmVec3*)&bindNormal, (kmVec3*)&bindNormal, &transformedNormal);

         object->geometry->vertices.v3b[weight->vertexIndex].vertex.x += bindVertex.x * weight->weight;
         object->geometry->vertices.v3b[weight->vertexIndex].vertex.y += bindVertex.y * weight->weight;
         object->geometry->vertices.v3b[weight->vertexIndex].vertex.z += bindVertex.z * weight->weight;
         object->geometry->vertices.v3b[weight->vertexIndex].normal.x += bindNormal.x * weight->weight;
         object->geometry->vertices.v3b[weight->vertexIndex].normal.y += bindNormal.y * weight->weight;
         object->geometry->vertices.v3b[weight->vertexIndex].normal.z += bindNormal.z * weight->weight;
      }
   }
}
Ejemplo n.º 5
0
void Mesh::normalize() {
    float dia = this->diameter();
    float scaling = 1.0 / dia;

    smlt::Mat4 scale_matrix;
    kmMat4Scaling(&scale_matrix, scaling, scaling, scaling);

    transform_vertices(scale_matrix);
}
Ejemplo n.º 6
0
uint8_t lite3d_scene_node_update(lite3d_scene_node *node)
{
    uint8_t updated = LITE3D_FALSE;
    SDL_assert(node);

    if (node->recalc)
    {
        kmMat4 transMat;
        kmMat4 scaleMat;
        kmQuaternionNormalize(&node->rotation,
            &node->rotation);

        kmMat4RotationQuaternion(&node->localView, &node->rotation);
        kmMat4Translation(&transMat,
            node->isCamera ? -node->position.x : node->position.x,
            node->isCamera ? -node->position.y : node->position.y,
            node->isCamera ? -node->position.z : node->position.z);

        if (node->scale.x != 1.0f ||
            node->scale.y != 1.0f ||
            node->scale.z != 1.0f)
        {
            kmMat4Scaling(&scaleMat, node->scale.x,
                node->scale.y,
                node->scale.z);

            kmMat4Multiply(&transMat, &transMat, &scaleMat);
        }

        if (node->rotationCentered)
            kmMat4Multiply(&node->localView,
            &transMat, &node->localView);
        else
            kmMat4Multiply(&node->localView,
            &node->localView, &transMat);

        if (node->baseNode)
        {
            kmMat4Multiply(&node->worldView,
                &node->baseNode->worldView, &node->localView);
        }
        else
        {
            node->worldView = node->localView;
        }
        
        kmMat3NormalMatrix(&node->normalModel, &node->worldView);

        node->recalc = LITE3D_FALSE;
        node->invalidated = LITE3D_TRUE;
        updated = LITE3D_TRUE;
    }

    return updated;
}
Ejemplo n.º 7
0
void CAFlashView::draw()
{
    CAView::draw();
    ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
    kmMat4 matrixP;
    kmMat4 matrixMV;
    kmMat4 matrixMVP;
    kmGLGetMatrix(KM_GL_PROJECTION, &matrixP );
    kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV );
    matrixMV.mat[13] = this->getFrame().size.height + matrixMV.mat[13];
    kmMat4Multiply(&matrixMVP, &matrixP, &matrixMV);
#if CC_ENABLE_GL_STATE_CACHE
    ccGLUseProgram(0);//valid program is NON_ZERO unsigned int
#endif
    CCSize size = this->getFrame().size;
    float localScaleX = size.width/ m_pFlash->getWidth();
    float localScaleY = -(size.height / m_pFlash->getHeight());
    float localScale = localScaleX > -localScaleY ? -localScaleY : localScaleX;
    kmMat4 matrixs;
    kmMat4Scaling(&matrixs, localScale, -localScale, getZOrder());
    kmMat4Multiply(&matrixMVP, &matrixMVP, &matrixs);
    m_pFlash->display(&matrixMVP);
    CHECK_GL_ERROR_DEBUG();
}
void kmGLScalef(float x, float y, float z)
{
	kmMat4 scaling;
	kmMat4Scaling(&scaling, x, y, z);
	kmMat4Multiply(current_stack->top, current_stack->top, &scaling);
}