//----------------------------------------------------------- //----------------------------------------------------------- void SpriteComponent::Render(RenderSystem* inpRenderSystem, CameraComponent* inpCam, ShaderPass ineShaderPass) { if (ineShaderPass == ShaderPass::k_ambient) { if(IsTextureSizeCacheValid() == false) { OnTransformChanged(); SetTextureSizeCacheValid(); } if(m_vertexPositionsValid == false) { //We have been transformed so we need to recalculate our vertices UpdateVertexPositions(); m_vertexPositionsValid = true; } m_spriteData.pMaterial = mpMaterial; //Add us to the render systems dynamic batch //If we force a batch flush here then the previous sprites //will be rendered. inpRenderSystem->GetDynamicSpriteBatchPtr()->Render(m_spriteData); } }
//---------------------------------------------------- //---------------------------------------------------- const Core::Sphere& SpriteComponent::GetBoundingSphere() { if(IsTextureSizeCacheValid() == false) { OnTransformChanged(); SetTextureSizeCacheValid(); } if(GetEntity() && m_isBSValid == false) { m_isBSValid = true; Core::Vector2 transformedSize = GetSize(); // Realign the origin Core::Vector2 anchorPoint = GetAnchorPoint(m_originAlignment, transformedSize * 0.5f); mBoundingSphere.vOrigin = GetEntity()->GetTransform().GetWorldPosition() - Core::Vector3(anchorPoint, 0.0f); mBoundingSphere.fRadius = std::sqrt((transformedSize.x * transformedSize.x) + (transformedSize.y * transformedSize.y)) * 0.5f; } return mBoundingSphere; }
//---------------------------------------------------- //---------------------------------------------------- const Core::AABB& SpriteComponent::GetAABB() { if(IsTextureSizeCacheValid() == false) { OnTransformChanged(); SetTextureSizeCacheValid(); } if(GetEntity() && m_isAABBValid == false) { m_isAABBValid = true; Core::Vector2 transformedSize = GetSize(); // Realign the origin Core::Vector2 anchorPoint = GetAnchorPoint(m_originAlignment, transformedSize * 0.5f); // Rebuild the box mBoundingBox.SetSize(Core::Vector3(transformedSize, 0.0f)); mBoundingBox.SetOrigin(GetEntity()->GetTransform().GetWorldPosition() - Core::Vector3(anchorPoint, 0.0f)); } return mBoundingBox; }
//---------------------------------------------------- //---------------------------------------------------- const OOBB& SpriteComponent::GetOOBB() { if(IsTextureSizeCacheValid() == false) { OnTransformChanged(); SetTextureSizeCacheValid(); } if(GetEntity() && m_isOOBBValid == false) { m_isOOBBValid = true; Vector2 transformedSize = GetSize(); // Realign the origin Vector2 anchorPoint = GetAnchorPoint(m_originAlignment, transformedSize * 0.5f); // Rebuild the box mOBBoundingBox.SetOrigin(Vector3(-anchorPoint, 0.0f)); mOBBoundingBox.SetSize(Vector3(transformedSize, 0.0f)); mOBBoundingBox.SetTransform(GetEntity()->GetTransform().GetWorldTransform()); } return mOBBoundingBox; }