void ChunkManager::initTree(ChunkTree& pChild) { boost::shared_ptr<Chunk>& pChunk = pChild.getValue(); AABB bounds = pChild.getParent()->getValue()->m_bounds; vec center = bounds.CenterPoint(); vec c0 = bounds.CornerPoint(pChild.getCorner().index()); AABB b0(vec(min(c0.x, center.x), min(c0.y, center.y), min(c0.z, center.z)), vec(max(c0.x, center.x), max(c0.y, center.y), max(c0.z, center.z))); pChunk = boost::make_shared<Chunk>(b0, 1.0f/pChild.getLevel(), this); pChunk->m_pTree = &pChild; *pChunk->m_workInProgress = true; m_chunkGeneratorQueue.push(pChild.getValueCopy()); }
void OBB::SetFrom(const AABB &aabb) { pos = aabb.CenterPoint(); r = aabb.HalfSize(); axis[0] = float3(1,0,0); axis[1] = float3(0,1,0); axis[2] = float3(0,0,1); }
void OBBSetFrom(OBB &obb, const AABB &aabb, const Matrix &m) { obb.pos = m.MulPos(aabb.CenterPoint()); float3 size = aabb.HalfSize(); obb.axis[0] = m.MulDir(float3(size.x, 0, 0)); obb.axis[1] = m.MulDir(float3(0, size.y, 0)); obb.axis[2] = m.MulDir(float3(0, 0, size.z)); obb.r.x = obb.axis[0].Normalize(); obb.r.y = obb.axis[1].Normalize(); obb.r.z = obb.axis[2].Normalize(); }
/// Set Christer Ericson's Real-Time Collision Detection, p.164. bool Plane::Intersects(const AABB &aabb) const { float3 c = aabb.CenterPoint(); float3 e = aabb.HalfDiagonal(); // Compute the projection interval radius of the AABB onto L(t) = aabb.center + t * plane.normal; float r = e[0]*Abs(normal[0]) + e[1]*Abs(normal[1]) + e[2]*Abs(normal[2]); // Compute the distance of the box center from plane. float s = Dot(normal, c) - d; return Abs(s) <= r; }
/// The Plane-AABB intersection is implemented according to Christer Ericson's Real-Time Collision Detection, p.164. [groupSyntax] bool Plane::Intersects(const AABB &aabb) const { vec c = aabb.CenterPoint(); vec e = aabb.HalfDiagonal(); // Compute the projection interval radius of the AABB onto L(t) = aabb.center + t * plane.normal; float r = e[0]*Abs(normal[0]) + e[1]*Abs(normal[1]) + e[2]*Abs(normal[2]); // Compute the distance of the box center from plane. // float s = Dot(normal, c) - d; float s = Dot(normal.xyz(), c.xyz()) - d; ///\todo Use the above form when Plane is SSE'ized. return Abs(s) <= r; }
void AABBTransformAsAABB(AABB &aabb, Matrix &m) { float3 newCenter = m.MulPos(aabb.CenterPoint()); float3 newDir; float3 h = aabb.HalfSize(); // The following is equal to taking the absolute value of the whole matrix m. newDir.x = ABSDOT3(m[0], h); newDir.y = ABSDOT3(m[1], h); newDir.z = ABSDOT3(m[2], h); aabb.minPoint = newCenter - newDir; aabb.maxPoint = newCenter + newDir; }
void ChunkManager::initTree1(ChunkTree& pChild) { boost::shared_ptr<Chunk>& pChunk = pChild.getValue(); AABB bounds = pChild.getParent()->getValue()->m_bounds; vec center = bounds.CenterPoint(); vec c0 = bounds.CornerPoint(pChild.getCorner().index()); AABB b0(vec(min(c0.x, center.x), min(c0.y, center.y), min(c0.z, center.z)), vec(max(c0.x, center.x), max(c0.y, center.y), max(c0.z, center.z))); pChunk = boost::make_shared<Chunk>(b0, 1.0f/pChild.getLevel(), this); pChunk->m_pTree = &pChild; pChunk->generateTerrain(); pChunk->generateMesh(); }
void OBBSetFrom(OBB &obb, const AABB &aabb, const Matrix &m) { assume(m.IsColOrthogonal()); // We cannot convert transform an AABB to OBB if it gets sheared in the process. assume(m.HasUniformScale()); // Nonuniform scale will produce shear as well. obb.pos = m.MulPos(aabb.CenterPoint()); obb.r = aabb.HalfSize(); obb.axis[0] = DIR_VEC(m.Col(0)); obb.axis[1] = DIR_VEC(m.Col(1)); obb.axis[2] = DIR_VEC(m.Col(2)); // If the matrix m contains scaling, propagate the scaling from the axis vectors to the half-length vectors, // since we want to keep the axis vectors always normalized in our representation. float matrixScale = obb.axis[0].LengthSq(); matrixScale = Sqrt(matrixScale); obb.r *= matrixScale; matrixScale = 1.f / matrixScale; obb.axis[0] *= matrixScale; obb.axis[1] *= matrixScale; obb.axis[2] *= matrixScale; // mathassert(vec::AreOrthogonal(obb.axis[0], obb.axis[1], obb.axis[2])); // mathassert(vec::AreOrthonormal(obb.axis[0], obb.axis[1], obb.axis[2])); ///@todo Would like to simply do the above, but instead numerical stability requires to do the following: vec::Orthonormalize(obb.axis[0], obb.axis[1], obb.axis[2]); }