Пример #1
0
//====================
// ボーンの行列を更新
//====================
void cPMDBone::updateMatrix( void )
{
	// クォータニオンと移動値からボーンのローカルマトリックスを作成
	QuaternionToMatrix( m_matLocal, &m_vec4Rotation );
	m_matLocal[3][0] = m_vec3Position.x + m_vec3Offset.x; 
	m_matLocal[3][1] = m_vec3Position.y + m_vec3Offset.y; 
	m_matLocal[3][2] = m_vec3Position.z + m_vec3Offset.z; 

	// 親があるなら親の回転を受け継ぐ
	if( m_pParentBone )	MatrixMultiply( m_matLocal, m_matLocal, m_pParentBone->m_matLocal );
}
Пример #2
0
void skinnedmesh_frame(skinnedmesh_t *sm,float frame) {
    int i,frame1,frame2;
    frame1 = (int)frame;
    frame -= frame1;
    if(frame1 >= sm->num_frame) frame1 %= sm->num_frame;
    frame2 = frame1 + 1;
    if(frame2 >= sm->num_frame) frame2 = 0;
    for(i = 0; i < sm->num_bone; i++) {
        float matrix_xyz[16],matrix_rot[16];
        float xyz[3],rot[4],a[3],b[3];
        VectorScale(sm->frame[frame1][i].xyz,1.0 - frame,a);
        VectorScale(sm->frame[frame2][i].xyz,frame,b);
        VectorAdd(a,b,xyz);
        QuaternionSlerp(sm->frame[frame1][i].rot,
            sm->frame[frame2][i].rot,frame,rot);
        MatrixTranslate(xyz[0],xyz[1],xyz[2],matrix_xyz);
        QuaternionToMatrix(rot,matrix_rot);
        MatrixMultiply(matrix_xyz,matrix_rot,sm->bone[i].matrix);
    }
    for(i = 0; i < sm->num_surface; i++) {
        int j;
        surface_t *surface = sm->surface[i];
        for(j = 0; j < surface->num_vertex; j++) {
            int k;
            VectorSet(0,0,0,surface->vertex[j].xyz);
            VectorSet(0,0,0,surface->vertex[j].normal);
            for(k = 0; k < surface->vertex[j].num_weight; k++) {
                float v[3];
                weight_t *weight = &surface->vertex[j].weight[k];
                VectorTransform(weight->xyz,
                    sm->bone[weight->bone].matrix,v);
                VectorScale(v,weight->weight,v);
                VectorAdd(surface->vertex[j].xyz,v,
                    surface->vertex[j].xyz);
                VectorTransformNormal(weight->normal,
                    sm->bone[weight->bone].matrix,v);
                VectorScale(v,weight->weight,v);
                VectorAdd(surface->vertex[j].normal,v,
                    surface->vertex[j].normal);
            }
        }
    }
}
void PivotCalibration2::TransformToMatrix(QIN_Transform_Type* trans_in, vtkMatrix4x4* outmatrix)
{
	auto rot_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
	// convert quaternion to matrix
	QuaternionToMatrix(rot_matrix, &(trans_in->q0));

	outmatrix->SetElement(3, 0, 0);
	outmatrix->SetElement(3, 1, 0);
	outmatrix->SetElement(3, 2, 0);
	outmatrix->SetElement(3, 3, 1);
	

	for (unsigned int i = 0; i<3; i++)
	{
		for (unsigned int j = 0; j<3; j++)
		{
			outmatrix->SetElement(i, j, rot_matrix->GetElement(i, j));
		}
	}
	outmatrix->SetElement(0,3,trans_in->x);
	outmatrix->SetElement(1,3,trans_in->y);
	outmatrix->SetElement(2,3,trans_in->z);
	outmatrix->SetElement(3,3,1);
}
/*
Description:
Convert raw transform to an matrix
Parameters:
index count from 0
*/
void PivotCalibration2::TransformToMatrix(QIN_Transform_Type* trans_in, QIN_Matrix_Type trans_out)
{
	auto tem_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
	// convert quaternion to matrix
	QuaternionToMatrix(tem_matrix,&(trans_in->q0));

	trans_out[3][0] = 0;
	trans_out[3][1] = 0;
	trans_out[3][2] = 0;
	trans_out[3][3] = 1;

	for (unsigned int i = 0; i<3; i++)
	{
		for (unsigned int j = 0; j<3; j++)
		{
			trans_out[i][j] = tem_matrix->GetElement(i,j);
			//outmatrix.SetElement(i, j, inmatrix.GetVnlMatrix().get(i, j));
		}
	}
	trans_out[0][3] = trans_in->x;
	trans_out[1][3] = trans_in->y;
	trans_out[2][3] = trans_in->z;
	trans_out[3][3] = 1;
}
// Render a frame
void Render()
{
    // Clear the back buffer 
    g_D3DDevCtx->ClearRenderTargetView(g_RenderTargetView, g_BackgroundColor);
    g_D3DDevCtx->ClearDepthStencilView(g_DepthStencilView, D3D11_CLEAR_DEPTH, 1, 0);

    // Set world/view/proj matrices and global shader constants
    float aspectRatio = (float)g_DepthStencilDesc.Width / g_DepthStencilDesc.Height;
    Matrix4x4 proj = Projection(FLOAT_PI/4, aspectRatio, 0.1f, 100.0f);
    float dist = g_CamDistance + 0.4f;
    Vector3 camPosInv = { dist * 0.3f, dist * 0.0f, dist * 2.0f };
    Matrix4x4 view = Translation(camPosInv);
    Matrix4x4 world = QuaternionToMatrix(g_SpongeRotation);
    SetShaderConstants(world, view, proj);

    // Draw the sponge
    DrawSponge();

	// Draw tweak bars
    TwDraw();

    // Present the information rendered in the back buffer to the front buffer (the screen)
    g_SwapChain->Present(0, 0);
}