CVertMeshViewer::CVertMeshViewer(UVertMesh* Mesh, CApplication* Window) : CMeshViewer(Mesh, Window) , AnimIndex(-1) { CVertMeshInstance *VertInst = new CVertMeshInstance(); VertInst->SetMesh(Mesh); Inst = VertInst; CVertMeshInstance *MeshInst = static_cast<CVertMeshInstance*>(Inst); // compute model center by Z-axis (vertical) CVec3 offset; const FBox &B = Mesh->BoundingBox; #if 1 VectorAdd(CVT(B.Min), CVT(B.Max), offset); offset.Scale(0.5f); MeshInst->BaseTransformScaled.TransformPointSlow(offset, offset); #else // scale/translate origin float z = (B.Max.Z + B.Min.Z) / 2; z = (z - Mesh->MeshOrigin.Z) * Mesh->MeshScale.Z; //!! bad formula offset.Set(0, 0, z); #endif offset[2] += Mesh->BoundingSphere.R / 20; // offset a bit up // offset view SetViewOffset(offset); // automatically scale view distance depending on model size float Radius = Mesh->BoundingSphere.R; if (Radius < 10) Radius = 10; SetDistScale(Mesh->MeshScale.X * Radius / 150); }
inline void TransformPosition(CVec3& pos) { Exchange(pos[1], pos[2]); pos.Scale(0.01f); }