void ModelViewerRender::RenderStaticNormals() { if(m_pModelMF1==NULL) return ; const float NORMAL_LENGTH=0.02f; uint32 meshCount=m_pModelMF1->m_Header.m_iNumMeshes; for(uint32 i=0;i<meshCount;++i) { SGPMF1Mesh &mesh=m_pModelMF1->m_pLOD0Meshes[i]; uint32 vertexCount=m_pModelMF1->m_pLOD0Meshes[i].m_iNumVerts; SGPVertex_UPOS_VERTEXCOLOR* pVert=new SGPVertex_UPOS_VERTEXCOLOR[vertexCount*2]; for(uint32 j=0;j<vertexCount;++j) { SGPMF1Vertex& currVert=mesh.m_pVertex[j]; Vector4D startPos,endPos; startPos.Set(currVert.vPos[0],currVert.vPos[1],currVert.vPos[2]); startPos=startPos*m_pStaticModel->getModelMatrix(); endPos.Set(currVert.vPos[0]+currVert.vNormal[0]*NORMAL_LENGTH,currVert.vPos[1]+\ currVert.vNormal[1]*NORMAL_LENGTH,currVert.vPos[2]+currVert.vNormal[2]*NORMAL_LENGTH); endPos=endPos*m_pStaticModel->getModelMatrix(); SetVertexPos(pVert[2*j],startPos.x,startPos.y,startPos.z); SetVertexColor(pVert[2*j],1.0f,1.0f,1.0f,1.0f); SetVertexPos(pVert[2*j+1],endPos.x,endPos.y,endPos.z); SetVertexColor(pVert[2*j+1],1.0f,1.0f,1.0f,1.0f); } m_pRenderDevice->GetVertexCacheManager()->RenderLines(2*vertexCount,pVert,false); delete [] pVert; } }
void ModelViewerRender::InitGround() { int vertIndex=0; for( int Row=-13; Row<=13; Row++ ) { SetVertexPos(m_SurfaceVertex[vertIndex],Row*0.5f,0,-13*0.5f); SetVertexColor(m_SurfaceVertex[vertIndex],((Row==0)?0:0.6f),((Row==0)?0:0.6f),((Row==0)?0:0.6f),1.0f); vertIndex++; SetVertexPos(m_SurfaceVertex[vertIndex],Row*0.5f,0,13*0.5f); SetVertexColor(m_SurfaceVertex[vertIndex],((Row==0)?0:0.6f),((Row==0)?0:0.6f),((Row==0)?0:0.6f),1.0f); vertIndex++; } for( int Col=-13; Col<=13; Col++ ) { SetVertexPos(m_SurfaceVertex[vertIndex],-13*0.5f,0,Col*0.5f); SetVertexColor(m_SurfaceVertex[vertIndex],(Col==0)?0:0.6f,(Col==0)?0:0.6f,(Col==0)?0:0.6f,1.0f); vertIndex++; SetVertexPos(m_SurfaceVertex[vertIndex],13*0.5f,0,Col*0.5f); SetVertexColor(m_SurfaceVertex[vertIndex],(Col==0)?0:0.6f,(Col==0)?0:0.6f,(Col==0)?0:0.6f,1.0f); vertIndex++; } }
void Sprite::Draw(ID3D12GraphicsCommandList* commandList){ SetVertexPos(vertex, pos, base, size, angle); UpdateVertex(vertex.data(),vertexResource.get()); SetConstantBuffer(commandList); DX12::SetTexture(commandList,fileName); UINT SizeTbl[] = { sizeof(DefaultVertex) }; UINT OffsetTbl[] = { 0 }; commandList->IASetVertexBuffers(0, 1, &vertexBufferView); commandList->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); commandList->DrawInstanced(4, 1, 0, 0); }
void ModelViewerRender::CalTranlsatedVertex(SGPVertex_UPOS_VERTEXCOLOR &vertex,Matrix4x4* pBoneMatrix,int meshIndex,int vertexIndex,BOOL bOrigin) { const float NORMAL_LENGTH=0.02f; SGPMF1Mesh& mesh=m_pModelMF1->m_pLOD0Meshes[meshIndex]; SGPMF1BoneGroup& boneGroup=m_pModelMF1->m_pBoneGroup[mesh.m_pVertexBoneGroupID[vertexIndex]]; SGPMF1Vertex& vert=mesh.m_pVertex[vertexIndex]; Vector4D result,origin; if(bOrigin) origin.Set(vert.vPos[0],vert.vPos[1],vert.vPos[2]); else origin.Set(vert.vPos[0]+vert.vNormal[0]*NORMAL_LENGTH,vert.vPos[1]+vert.vNormal[1]*NORMAL_LENGTH,\ vert.vPos[2]+vert.vNormal[2]*NORMAL_LENGTH); uint8 totalWeight=0; if(boneGroup.BoneWeight.x!=0) { totalWeight+=boneGroup.BoneWeight.x; result=(origin*pBoneMatrix[boneGroup.BoneIndex.x])*(float)boneGroup.BoneWeight.x; } if(boneGroup.BoneWeight.y!=0) { totalWeight+=boneGroup.BoneWeight.y; result=result+(origin*pBoneMatrix[boneGroup.BoneIndex.y])*(float)boneGroup.BoneWeight.y; } if(boneGroup.BoneWeight.z!=0) { totalWeight+=boneGroup.BoneWeight.z; result=result+(origin*pBoneMatrix[boneGroup.BoneIndex.z])*(float)boneGroup.BoneWeight.z; } if(boneGroup.BoneWeight.w!=0) { totalWeight+=boneGroup.BoneWeight.w; result=result+(origin*pBoneMatrix[boneGroup.BoneIndex.w])*(float)boneGroup.BoneWeight.w; } result*=1/(float)totalWeight; SetVertexPos(vertex,result.x,result.y,result.z); SetVertexColor(vertex,1.0f,1.0f,1.0f,1.0f); }
void ModelViewerRender::RenderCoordinateAxis() { Matrix4x4 matView, matProj, matInvViewProj; Vector4D OrigTo; // proj position Vector4D vAxisOrig( -0.75f, -0.75f, 0.1f); m_pRenderDevice->getViewMatrix(matView); m_pRenderDevice->getProjMatrix(matProj); // Inverse view*proj to get "proj->world" transform matInvViewProj.InverseOf( matView*matProj ); // move the obj to leftbottom of camera then transfer to world coordinate Vector4D Orig = vAxisOrig * matInvViewProj; Orig.x /= Orig.w; Orig.y /= Orig.w; Orig.z /= Orig.w; Orig.w = 1; // draw the lines stand for coordinate const float LINE_LENGTH = 0.002f; // RED X OrigTo = Orig + Vector4D(LINE_LENGTH,0,0); SetVertexPos(m_AxisVertex[0],Orig.x,Orig.y,Orig.z); SetVertexColor(m_AxisVertex[0],1.0f,0.0f,0.0f,1.0f); SetVertexPos(m_AxisVertex[1],OrigTo.x,OrigTo.y,OrigTo.z); SetVertexColor(m_AxisVertex[1],1.0f,0.0f,0.0f,1.0f); // GREEN Y OrigTo = Orig + Vector4D(0,LINE_LENGTH,0); SetVertexPos(m_AxisVertex[2],Orig.x,Orig.y,Orig.z); SetVertexColor(m_AxisVertex[2],0.0f,1.0f,0.0f,1.0f); SetVertexPos(m_AxisVertex[3],OrigTo.x,OrigTo.y,OrigTo.z); SetVertexColor(m_AxisVertex[3],0.0f,1.0f,0.0f,1.0f); // BLUE Z OrigTo = Orig + Vector4D(0,0,LINE_LENGTH); SetVertexPos(m_AxisVertex[4],Orig.x,Orig.y,Orig.z); SetVertexColor(m_AxisVertex[4],0.0f,0.0f,1.0f,1.0f); SetVertexPos(m_AxisVertex[5],OrigTo.x,OrigTo.y,OrigTo.z); SetVertexColor(m_AxisVertex[5],0.0f,0.0f,1.0f,1.0f); m_pRenderDevice->GetVertexCacheManager()->RenderLines(6,m_AxisVertex,false); }
void ModelViewerRender::RenderBones() { if(m_pModelMF1==NULL) return ; // const float boneOffset[3]={0.05f,0.05f,0.05f}; const float boneOffset[3]={0.0f,0.0f,0.0f}; uint32 nBoneCount=m_pModelMF1->m_iNumBones; SGPMF1Bone* pBones=m_pModelMF1->m_pBones; float* pBoneMatrixs=m_pDynamicModel->getBonesMatrix(); SGPVertex_UPOS_VERTEXCOLOR vertex[2]; SetVertexColor(vertex[0],1.0f,1.0f,1.0f,1.0f); SetVertexColor(vertex[1],1.0f,1.0f,1.0f,1.0f); for(uint32 i=0;i<nBoneCount;++i) { uint32 childCount=pBones[i].m_iNumChildId; if(childCount!=0) { Matrix4x4 matFrame0; matFrame0.InverseOf(pBones[i].m_matFrame0Inv); Matrix4x4 matAnimation; matAnimation.Identity(); matAnimation._11=pBoneMatrixs[12*i]; matAnimation._21=pBoneMatrixs[12*i+1]; matAnimation._31=pBoneMatrixs[12*i+2]; matAnimation._41=pBoneMatrixs[12*i+3]; matAnimation._12=pBoneMatrixs[12*i+4]; matAnimation._22=pBoneMatrixs[12*i+5]; matAnimation._32=pBoneMatrixs[12*i+6]; matAnimation._42=pBoneMatrixs[12*i+7]; matAnimation._13=pBoneMatrixs[12*i+8]; matAnimation._23=pBoneMatrixs[12*i+9]; matAnimation._33=pBoneMatrixs[12*i+10]; matAnimation._43=pBoneMatrixs[12*i+11]; Matrix4x4 matOrigin=matFrame0*matAnimation*m_pDynamicModel->getModelMatrix(); // SetVertexPos(vertex[0],matOrigin._41+0.05f,matOrigin._42+0.05f,matOrigin._43+0.05f); SetVertexPos(vertex[0],matOrigin._41+boneOffset[0],matOrigin._42+boneOffset[1],matOrigin._43+boneOffset[2]); if(pBones[i].m_sParentID==0xFFFF) { AABBox aabox=m_pModelMF1->m_MeshAABBox; float length=(aabox.vcMax-aabox.vcMin).GetLength()/150.0f; m_pRenderDevice->GetVertexCacheManager()->RenderDetailSphere(Vector3D(matOrigin._41+boneOffset[0],\ matOrigin._42+boneOffset[1],matOrigin._43+boneOffset[2]),length,5,5,Colour(255,255,255)); } for(uint32 j=0;j<childCount;++j) { uint16 index=pBones[i].m_ChildIds[j]; matFrame0.InverseOf(pBones[index].m_matFrame0Inv); matAnimation.Identity(); matAnimation._11=pBoneMatrixs[12*index]; matAnimation._21=pBoneMatrixs[12*index+1]; matAnimation._31=pBoneMatrixs[12*index+2]; matAnimation._41=pBoneMatrixs[12*index+3]; matAnimation._12=pBoneMatrixs[12*index+4]; matAnimation._22=pBoneMatrixs[12*index+5]; matAnimation._32=pBoneMatrixs[12*index+6]; matAnimation._42=pBoneMatrixs[12*index+7]; matAnimation._13=pBoneMatrixs[12*index+8]; matAnimation._23=pBoneMatrixs[12*index+9]; matAnimation._33=pBoneMatrixs[12*index+10]; matAnimation._43=pBoneMatrixs[12*index+11]; matOrigin=matFrame0*matAnimation*m_pDynamicModel->getModelMatrix(); SetVertexPos(vertex[1],matOrigin._41+boneOffset[0],matOrigin._42+boneOffset[1],matOrigin._43+boneOffset[2]); m_pRenderDevice->GetVertexCacheManager()->RenderLines(2,vertex,false); } } else if(pBones[i].m_sParentID==0xFFFF)//the bone don't have children { Matrix4x4 matFrame0; matFrame0.InverseOf(pBones[i].m_matFrame0Inv); Matrix4x4 matAnimation; matAnimation.Identity(); matAnimation._11=pBoneMatrixs[12*i]; matAnimation._21=pBoneMatrixs[12*i+1]; matAnimation._31=pBoneMatrixs[12*i+2]; matAnimation._41=pBoneMatrixs[12*i+3]; matAnimation._12=pBoneMatrixs[12*i+4]; matAnimation._22=pBoneMatrixs[12*i+5]; matAnimation._32=pBoneMatrixs[12*i+6]; matAnimation._42=pBoneMatrixs[12*i+7]; matAnimation._13=pBoneMatrixs[12*i+8]; matAnimation._23=pBoneMatrixs[12*i+9]; matAnimation._33=pBoneMatrixs[12*i+10]; matAnimation._43=pBoneMatrixs[12*i+11]; Matrix4x4 matOrigin=matFrame0*matAnimation*m_pDynamicModel->getModelMatrix(); AABBox aabox=m_pModelMF1->m_MeshAABBox; float length=(aabox.vcMax-aabox.vcMin).GetLength()/150.0f; m_pRenderDevice->GetVertexCacheManager()->RenderDetailSphere(Vector3D(matOrigin._41+boneOffset[0],\ matOrigin._42+boneOffset[1],matOrigin._43+boneOffset[2]),length,5,5,Colour(255,255,255)); } } }