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); }
void CMeshViewer::InitViewerPosition(const CVec3 &Mins, const CVec3 &Maxs) { CVec3 tmp, Center; VectorAdd(Maxs, Mins, tmp); VectorScale(tmp, 0.5f, Center); VectorSubtract(Maxs, Center, tmp); float radius = tmp.GetLength(); SetViewOffset(Center); SetDistScale((radius + 10) / 230); MoveCamera(20, 20); }
CStatMeshViewer::CStatMeshViewer(CStaticMesh* Mesh0, CApplication* Window) : CMeshViewer(Mesh0->OriginalMesh, Window) , Mesh(Mesh0) { guard(CStatMeshViewer::CStatMeshViewer); CStatMeshInstance *StatInst = new CStatMeshInstance(); StatInst->SetMesh(Mesh); Inst = StatInst; #if 0 // compute model center CVec3 offset; offset[0] = (Mesh->BoundingBox.Max.X + Mesh->BoundingBox.Min.X) / 2; offset[1] = (Mesh->BoundingBox.Max.Y + Mesh->BoundingBox.Min.Y) / 2; offset[2] = (Mesh->BoundingBox.Max.Z + Mesh->BoundingBox.Min.Z) / 2; offset[2] += Mesh->BoundingSphere.R / 20; // offset a bit up SetViewOffset(offset); // automatically scale view distance depending on model size SetDistScale(Mesh->BoundingSphere.R / 150); #else //?? if Lods.Count > 0 && Lods[0].Verts.Num() > 0 CVec3 Mins, Maxs; if (Mesh0->Lods.Num()) { const CStaticMeshLod &Lod = Mesh0->Lods[0]; ComputeBounds(&Lod.Verts[0].Position, Lod.NumVerts, sizeof(CStaticMeshVertex), Mins, Maxs); } else { Mins = Maxs = nullVec3; } InitViewerPosition(Mins, Maxs); #endif unguard; }