Esempio n. 1
0
cxVec2f cxViewPointToWindowPoint(cxAny pview,cxVec2f vPoint)
{
    cxView this = pview;
    cxView pv = this;
    cxVec3f out;
    kmVec3Fill(&out, vPoint.x, vPoint.y, 0);
    while (pv != NULL && pv->parentView != NULL) {
        kmVec3Transform(&out, &out, &pv->anchorMatrix);
        kmVec3Transform(&out, &out, &pv->normalMatrix);
        pv = pv->parentView;
    }
    return cxVec2fv(out.x, out.y);
}
Esempio n. 2
0
/* \brief calcualate view matrix */
static void _glhckCameraViewMatrix(glhckCamera *object)
{
   kmMat4 rotation, tmp;
   kmVec3 upvector;
   CALL(2, "%p", object);
   assert(object);

   /* build rotation for upvector */
   kmMat4RotationAxisAngle(&rotation, &(kmVec3){0,0,1},
	 kmDegreesToRadians(object->object->view.rotation.z));
   kmMat4RotationAxisAngle(&tmp, &(kmVec3){0,1,0},
	 kmDegreesToRadians(object->object->view.rotation.y));
   kmMat4Multiply(&rotation, &rotation, &tmp);
   kmMat4RotationAxisAngle(&tmp, &(kmVec3){1,0,0},
	 kmDegreesToRadians(object->object->view.rotation.x));
   kmMat4Multiply(&rotation, &rotation, &tmp);

   /* assuming upvector is normalized */
   kmVec3Transform(&upvector, &object->view.upVector, &rotation);

   /* build view matrix */
   kmMat4LookAt(&object->view.view, &object->object->view.translation,
	 &object->object->view.target, &upvector);
   kmMat4Multiply(&object->view.viewProj,
	 &object->view.projection, &object->view.view);
   glhckFrustumBuild(&object->frustum, &object->view.viewProj);
}
Esempio n. 3
0
Point Node::convertToNodeSpace(const Point& worldPoint) const
{
    kmMat4 tmp = getWorldToNodeTransform();
    kmVec3 vec3 = {worldPoint.x, worldPoint.y, 0};
    kmVec3 ret;
    kmVec3Transform(&ret, &vec3, &tmp);
    return Point(ret.x, ret.y);
}
Esempio n. 4
0
Point Node::convertToWorldSpace(const Point& nodePoint) const
{
    kmMat4 tmp = getNodeToWorldTransform();
    kmVec3 vec3 = {nodePoint.x, nodePoint.y, 0};
    kmVec3 ret;
    kmVec3Transform(&ret, &vec3, &tmp);
    return Point(ret.x, ret.y);

}
Esempio n. 5
0
/* update skeletal animation */
static void dlObjectUpdateSkeletal( dlObject *object )
{
   unsigned int x;
   dlBone         *bone;
   dlVertexWeight *weight;

   kmVec3 tStance;
   kmMat4 boneMat;
   dlAnimator *animator;

   CALL("%p", object);

   animator = object->animator;

   /* TO-DO: Shader implentation */
   /* Reset all vertices to 0 here */
   x = 0;
   for(; x != object->vbo->v_num; ++x)
   {
      object->vbo->vertices[x].x = 0;
      object->vbo->vertices[x].y = 0;
      object->vbo->vertices[x].z = 0;
   }

   bone = animator->bone;
   for(; bone; bone = bone->next)
   {
      boneMat = bone->globalMatrix;
      weight = bone->weight;
      for(; weight; weight = weight->next)
      {
         /* Get bone matrices */
         /* and shift t-stance vertices */

         tStance  = object->vbo->tstance[weight->vertex];
         kmVec3Transform( &tStance, &tStance, &boneMat );

         object->vbo->vertices[weight->vertex].x += tStance.x * weight->value;
         object->vbo->vertices[weight->vertex].y += tStance.y * weight->value;
         object->vbo->vertices[weight->vertex].z += tStance.z * weight->value;

         /*
          * index  = object->bone[i]->weight[x].vertex;
          * weight = object->bone[i]->weight[x].weight;
          * kmVec3 tStance = TSTANCE[ index ];
          * tStance *= boneMat;
          *
          * vbo->vertices[index].x += tStance.x*weight;
          * vbo->vertices[index].y += tStance.y*weight;
          * vbo->vertices[index].z += tStance.z*weight;
          */
      }
   }

   /* VBO needs update */
   object->vbo->up_to_date = 0;
}
Esempio n. 6
0
cxVec2f cxWindowPointToViewPoint(cxAny pview,cxVec2f wPoint)
{
    cxView this = pview;
    cxView pv = this;
    cxVec3f out;
    cxMatrix4f matrix;
    kmVec3Fill(&out, wPoint.x, wPoint.y, 0);
    cxArray list = CX_ALLOC(cxArray);
    while (pv != NULL && pv->parentView != NULL) {
        cxArrayAppend(list, pv);
        pv = pv->parentView;
    }
    CX_ARRAY_REVERSE(list, ele){
        pv = cxArrayObject(ele);
        kmMat4Inverse(&matrix, &pv->normalMatrix);
        kmVec3Transform(&out, &out, &matrix);
        kmMat4Inverse(&matrix, &pv->anchorMatrix);
        kmVec3Transform(&out, &out, &matrix);
    }
Esempio n. 7
0
void Renderer::convertToWorldCoordinates(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView)
{
//    kmMat4 matrixP, mvp;
//    kmGLGetMatrix(KM_GL_PROJECTION, &matrixP);
//    kmMat4Multiply(&mvp, &matrixP, &modelView);

    for(ssize_t i=0; i<quantity; ++i) {
        V3F_C4B_T2F_Quad *q = &quads[i];

        kmVec3 *vec1 = (kmVec3*)&q->bl.vertices;
        kmVec3Transform(vec1, vec1, &modelView);

        kmVec3 *vec2 = (kmVec3*)&q->br.vertices;
        kmVec3Transform(vec2, vec2, &modelView);

        kmVec3 *vec3 = (kmVec3*)&q->tr.vertices;
        kmVec3Transform(vec3, vec3, &modelView);

        kmVec3 *vec4 = (kmVec3*)&q->tl.vertices;
        kmVec3Transform(vec4, vec4, &modelView);
    }
}
Esempio n. 8
0
kmVec3 *lite3d_scene_node_world_position(lite3d_scene_node *node, kmVec3 *pos)
{
    SDL_assert(node && pos);

    if (node->baseNode)
    {
        kmVec3Transform(pos, &node->position, &node->baseNode->worldView);
    }
    else
    {
        *pos = node->position;
    }
    
    return pos;
}
Esempio n. 9
0
bool Transform::pointInside(float x,float y,float& ox,float& oy)
{
    kmMat4 t_mat;
    kmMat4Inverse(&t_mat, &m_matrix);
    kmVec3 outpos;
    kmVec3 inpos;
//    float nx = x*2/Device::GetInstance()->getCurrentCanvas()->getLayerWidth()-1;
//    float ny = -y*2/Device::GetInstance()->getCurrentCanvas()->getLayerHeight()+1;
    kmVec3Fill(&inpos,x,y,0);
    kmVec3Transform(&outpos,&inpos,&t_mat);
    ox = outpos.x;
    oy = outpos.y;
    if (outpos.x >= 0 &&
        outpos.y >= 0 &&
        outpos.x < m_width&&
        outpos.y < m_height)
    {
        return true;
    }
    return false;
}
Esempio n. 10
0
/* draw skeleton */
void dlObjectDrawSkeleton( dlObject *object )
{
#if 0
   dlBone *bone;
   kmVec3 pos;

   if(!object)
      return;
   if(!object->animator)
      return;

   glDisable( GL_DEPTH_TEST );
   glBegin( GL_LINES );
   bone = object->animator->bone;
   for(; bone; bone = bone->next)
   {
      pos.x = 5; pos.y = 5; pos.z = 5;
      kmVec3Transform( &pos, &pos,  &bone->globalMatrix );
      glVertex3f( pos.x, pos.y, pos.z );
   }
   glEnd();
   glEnable( GL_DEPTH_TEST );
#endif
}
Esempio n. 11
0
void CSkin::CalcSkelAnim(const CAnimationController::BoneMatrixMap &matrices)
{
    CVertexPT *vertices = new CVertexPT[m_uVertexCount];
    for(size_t i = 0; i < m_uVertexCount; ++i)
    {
        const CVertexPTB &vertex = m_vertices[i];
        CVertexPT &vertex1 = vertices[i];
        if(matrices.empty())
        {
            vertex1.position = vertex.position;
            vertex1.tex = vertex.tex;
            continue;
        }

        kmVec3  pos;
        kmVec3Fill(&pos,vertex.position.x,vertex.position.y, vertex.position.z);

        kmVec3 finalpos;
        kmMat4 mat, mat2, mat3, mat4;
        if(vertex.bones.x >= 0)
        {
            auto itr = matrices.find(static_cast<ESkeletonBoneType>(vertex.bones.x));
            BEATS_ASSERT(itr != matrices.end());
            mat = itr->second;
            kmVec3 postmp;
            kmVec3Transform(&postmp,&pos,&mat);
            kmVec3Scale(&postmp, &postmp, vertex.weights.x);
            finalpos = postmp;
        }
        if(vertex.bones.y >= 0)
        {
            auto itr = matrices.find(static_cast<ESkeletonBoneType>(vertex.bones.y));
            BEATS_ASSERT(itr != matrices.end());
            mat2 = itr->second;
            kmVec3 postmp;
            kmVec3Transform(&postmp,&pos,&mat2);
            kmVec3Scale(&postmp, &postmp, vertex.weights.y);
            kmVec3Add(&finalpos,&finalpos,&postmp);
        }
        if(vertex.bones.z >= 0)
        {
            auto itr = matrices.find(static_cast<ESkeletonBoneType>(vertex.bones.z));
            BEATS_ASSERT(itr != matrices.end());
            mat3 = itr->second;
            kmVec3 postmp;
            kmVec3Transform(&postmp,&pos,&mat3);
            kmVec3Scale(&postmp, &postmp, vertex.weights.z);
            kmVec3Add(&finalpos,&finalpos,&postmp);
        }
        if(vertex.bones.w >= 0)
        {
            auto itr = matrices.find(static_cast<ESkeletonBoneType>(vertex.bones.w));
            BEATS_ASSERT(itr != matrices.end());
            mat4 = itr->second;
            kmVec3 postmp;
            kmVec3Transform(&postmp,&pos,&mat4);
            kmVec3Scale(&postmp, &postmp, vertex.weights.w);
            kmVec3Add(&finalpos,&finalpos,&postmp);
        }
        vertex1.position = finalpos;
        
        vertex1.tex = vertex.tex;
    }

    buildVBOVertex(vertices, m_uVertexCount*sizeof(CVertexPT));
    BEATS_SAFE_DELETE_ARRAY(vertices);
}
Esempio n. 12
0
Vector3 Lighting::ECTransform(const Vector3& vec, Matrix4 *mat)
{
	Vector3 ECVec;
	kmVec3Transform(&ECVec, &vec, mat);
	return ECVec;
}