void SNPointLight::GetContainerBoundingSphere(Sphere &cSphere) { // The sphere has always the 'range' as radius cSphere.SetRadius(m_fRange); // The sphere is always within the scene node origin cSphere.SetPos(GetTransform().GetPosition()); }
/** * @brief * Calculates the sphere surrounding the enclosed area */ void PlaneSet::CalculateSphere(Sphere &cSphere) const { // Init sphere cSphere.SetPos(); cSphere.SetRadius(); // Find all plane intersection points Vector3 vD; Array<Vector3> lstPoints; for (uint32 nP1=0; nP1<m_lstPlane.GetNumOfElements(); nP1++) { const Plane &cP1 = m_lstPlane[nP1]; for (uint32 nP2=0; nP2<m_lstPlane.GetNumOfElements(); nP2++) { const Plane cP2 = m_lstPlane[nP2]; if (nP2 != nP1) { for (uint32 nP3=0; nP3<m_lstPlane.GetNumOfElements(); nP3++) { const Plane &cP3 = m_lstPlane[nP3]; if (nP3 != nP1 && nP3 != nP2) { Vector3 vRes; if (Intersect::PlanePlanePlane(cP1, cP2, cP3, vRes)) { lstPoints.Add(vRes); vD += vRes; } } } } } } // Get sphere position and radius if (lstPoints.GetNumOfElements()) { vD /= static_cast<float>(lstPoints.GetNumOfElements()); cSphere.SetPos(vD); float fMaxLength = 0.0f; for (uint32 i=0; i<lstPoints.GetNumOfElements(); i++) { const Vector3 &vP = lstPoints[i]; const float fLength = (vP-vD).GetLength(); if (fLength > fMaxLength) fMaxLength = fLength; } cSphere.SetRadius(fMaxLength); } }
// Load assets bool ModuleSceneIntro::Start() { LOG("Loading Intro assets"); bool ret = true; App->camera->Move(vec3(1.0f, 1.0f, 0.0f)); App->camera->LookAt(vec3(0, 0, 0)); // TODO 2: Chain few N spheres together to form a snake Sphere s; s.SetPos(0, 3, 0); Sphere s2; s2.SetPos(4, 3, 0); PhysBody3D* bodyA = App->physics->AddBody(s); PhysBody3D* bodyB = App->physics->AddBody(s2); vec3 vA = { 2, 0, 0 }; vec3 vB = { -2, 0, 0 }; vec3 aA = { 0, 1, 0 }; vec3 aB = { 0, 1, 0 }; App->physics->CreateHingeConstraint(bodyA, bodyB, vA, vB, aA, aB); /* for (int i = 0; i < MAX_SNAKE; ++i) { s_snake[i] = Sphere(MAX_SNAKE - i); //s_snake[i].SetPos( MAX_SNAKE - i, 0, MAX_SNAKE + i ); pb_snake[i] = App->physics->AddBody(s_snake[i]); if (i > 0) { App->physics->Create2PointConstraint(pb_snake[i - 1], pb_snake[i], { 0, 0, 1 + s_snake[i - 1].radius }, { 0, 0, -1 - s_snake[i].radius }); } } */ // TODO 4: Chain few N spheres together to form a a bike's sphere // Be sure to put the right axis return ret; }