Exemplo n.º 1
0
 //-----------------------------------------------------------
 //-----------------------------------------------------------
 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);
     }
 }
Exemplo n.º 2
0
void SpatialNode::SetTransform(const Vector3& newPosition, const Quaternion& newRotation, const Vector3& newScale)
{
    position = newPosition;
    rotation = newRotation;
    scale = newScale;
    OnTransformChanged();
}
Exemplo n.º 3
0
void SpatialNode::Rotate(const Quaternion& delta, TransformSpace space)
{
    SpatialNode* parentNode = SpatialParent();
    
    switch (space)
    {
    case TS_LOCAL:
        rotation = (rotation * delta).Normalized();
        break;

    case TS_PARENT:
        rotation = (delta * rotation).Normalized();
        break;

    case TS_WORLD:
        if (!parentNode)
            rotation = (delta * rotation).Normalized();
        else
        {
            Quaternion worldRotation = WorldRotation();
            rotation = rotation * worldRotation.Inverse() * delta * worldRotation;
        }
        break;
    }

    OnTransformChanged();
}
Exemplo n.º 4
0
		//----------------------------------------------------------------
		/// Move By
		///
		/// @param X Component
		/// @param Y Component
		/// @param Z Component
		//----------------------------------------------------------------
		void Transform::MoveBy(f32 infX, f32 infY, f32 infZ)
		{
			mvPosition.x += infX;
			mvPosition.y += infY;
			mvPosition.z += infZ;
			
			OnTransformChanged();
		}
Exemplo n.º 5
0
		//----------------------------------------------------------------
		/// Scale By
		///
		/// Scale along each axis by the given amount
		///
		/// @param Axis vector
		//----------------------------------------------------------------
		void Transform::ScaleBy(const Vector3 &Vec)
		{
			mvScale.x *= Vec.x;
			mvScale.y *= Vec.y;
			mvScale.z *= Vec.z;
			
			OnTransformChanged();
		}
Exemplo n.º 6
0
		//----------------------------------------------------------------
		/// Scale By
		///
		/// Scale along each axis by the given amount
		///
		/// @param X Component
		/// @param Y Component
		/// @param Z Component
		//----------------------------------------------------------------
		void Transform::ScaleBy(f32 inX, f32 inY, f32 inZ)
		{
			mvScale.x *= inX;
			mvScale.y *= inY;
			mvScale.z *= inZ;
			
			OnTransformChanged();
		}
Exemplo n.º 7
0
		//----------------------------------------------------------------
		/// Scale By
		///
		/// Scale uniformly by the given amount
		///
		/// @param Scale factor
		//----------------------------------------------------------------
		void Transform::ScaleBy(f32 inScale)
		{
			mvScale.x *= inScale;
			mvScale.y *= inScale;
			mvScale.z *= inScale;
						  
			OnTransformChanged();
		}
Exemplo n.º 8
0
 //----------------------------------------------------------------
 /// Set Position Scale Orientation
 ///
 /// @param Position vector
 /// @param Scale vector
 /// @param Orientation quaternion
 //----------------------------------------------------------------
 void Transform::SetPositionScaleOrientation(const Vector3& invPos, const Vector3& invScale, const Quaternion& invOrientation)
 {
     mvPosition = invPos;
     mvScale = invScale;
     mqOrientation = invOrientation;
     
     OnTransformChanged();
 }
Exemplo n.º 9
0
		//----------------------------------------------------------------
		/// Scale To
		///
		/// Scale each axis to the given amount
		///
		/// @param Axis vector
		//----------------------------------------------------------------
		void Transform::ScaleTo(const Vector3 &Vec)
		{
            if(mvScale == Vec)
                return;
            
			mvScale = Vec;
			
			OnTransformChanged();
		}
Exemplo n.º 10
0
		//----------------------------------------------------------------
		/// Set Orientation
		///
		/// @param Orientation quaternion
		//----------------------------------------------------------------
		void Transform::SetOrientation(const Quaternion & inqOrientation)
		{
            if(mqOrientation == inqOrientation)
                return;
            
			mqOrientation = inqOrientation;
			
			OnTransformChanged();
		}
Exemplo n.º 11
0
		//----------------------------------------------------------------
		/// Set Position
		///
		/// @param Position vector
		//----------------------------------------------------------------
		void Transform::SetPosition(const Vector3 &invPos)
		{
            if(mvPosition == invPos)
                return;
            
			mvPosition = invPos;
            
			OnTransformChanged();
		}
Exemplo n.º 12
0
 //-----------------------------------------------------------
 //-----------------------------------------------------------
 void SpriteComponent::SetTextureAtlasId(const std::string& in_atlasId)
 {
     CS_ASSERT(m_textureAtlas != nullptr, "SpriteComponent: Cannot set texture atlas id until atlas has been set");
     
     OnTransformChanged();
     
     m_hashedTextureAtlasId = HashCRC32::GenerateHashCode(in_atlasId);
     m_uvs = m_textureAtlas->GetFrameUVs(m_hashedTextureAtlasId);
 }
Exemplo n.º 13
0
 //----------------------------------------------------------------
 /// Set Local Transform
 ///
 /// This will overwrite any local previous transformations
 ///
 /// @param Objects transformation matrix
 //----------------------------------------------------------------
 void Transform::SetLocalTransform(const Matrix4& inmatTransform)
 {
     inmatTransform.Decompose(mvPosition, mvScale, mqOrientation);
     
     mmatTransform = inmatTransform;
     
     OnTransformChanged();
     
     mbIsTransformCacheValid = false;
 }
Exemplo n.º 14
0
		//----------------------------------------------------------------
		/// Scale To
		///
		/// Scale each axis to the given amount
		///
		/// @param X Component
		/// @param Y Component
		/// @param Z Component
		//----------------------------------------------------------------
		void Transform::ScaleTo(f32 inX, f32 inY, f32 inZ)
		{
            if(mvScale.x == inX && mvScale.y == inY && mvScale.z == inZ)
                return;
            
			mvScale.x = inX;
			mvScale.y = inY;
			mvScale.z = inZ;
			
			OnTransformChanged();
		}
Exemplo n.º 15
0
		//----------------------------------------------------------------
		/// Scale To
		///
		/// Scale uniformly to the given amount
		///
		/// @param Scale factor
		//----------------------------------------------------------------
		void Transform::ScaleTo(f32 inScale)
		{
            if(mvScale.x == inScale && mvScale.y == inScale && mvScale.z == inScale)
                return;
            
			mvScale.x = inScale;
			mvScale.y = inScale;
			mvScale.z = inScale;
			
			OnTransformChanged();
		}
Exemplo n.º 16
0
 //----------------------------------------------------------------
 /// Set World Transform
 ///
 /// This will overwrite any parent or previous transformations
 ///
 /// @param Objects transformation matrix
 //----------------------------------------------------------------
 void Transform::SetWorldTransform(const Matrix4& inmatTransform)
 {
     inmatTransform.Decompose(mvWorldPosition, mvWorldScale, mqWorldOrientation);
     
     mmatWorldTransform = inmatTransform;
     
     OnTransformChanged();
     
     mbIsTransformCacheValid = true;
     mbIsParentTransformCacheValid = true;
 }
Exemplo n.º 17
0
        //----------------------------------------------------------------
		/// Set Position
		///
		/// @param X Component
		/// @param Y Component
		/// @param Z Component
		//----------------------------------------------------------------
		void Transform::SetPosition(f32 infX, f32 infY, f32 infZ)
		{
            if(mvPosition.x == infX && mvPosition.y == infY && mvPosition.z == infZ)
                return;
            
			mvPosition.x = infX;
			mvPosition.y = infY;
			mvPosition.z = infZ;
            
			OnTransformChanged();
		}
Exemplo n.º 18
0
void SpatialNode::SetScale(const Vector3& newScale)
{
    scale = newScale;
    // Make sure scale components never go to exactly zero, to prevent problems with decomposing the world matrix
    if (scale.x == 0.0f)
        scale.x = M_EPSILON;
    if (scale.y == 0.0f)
        scale.y = M_EPSILON;
    if (scale.z == 0.0f)
        scale.z = M_EPSILON;

    OnTransformChanged();
}
Exemplo n.º 19
0
		//----------------------------------------------------
		//----------------------------------------------------
		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;
		}
Exemplo n.º 20
0
void SpatialNode::Translate(const Vector3& delta, TransformSpace space)
{
    SpatialNode* parentNode = SpatialParent();

    switch (space)
    {
    case TS_LOCAL:
        // Note: local space translation disregards local scale for scale-independent movement speed
        position += rotation * delta;
        break;

    case TS_PARENT:
        position += delta;
        break;

    case TS_WORLD:
        position += !parentNode ? delta : parentNode->WorldTransform().Inverse() * Vector4(delta, 0.0f);
        break;
    }

    OnTransformChanged();
}
Exemplo n.º 21
0
void SpatialNode::RotateAround(const Vector3& point, const Quaternion& delta, TransformSpace space)
{
    SpatialNode* parentNode = SpatialParent();
    Vector3 parentSpacePoint;
    Quaternion oldRotation = rotation;

    switch (space)
    {
    case TS_LOCAL:
        parentSpacePoint = Transform() * point;
        rotation = (rotation * delta).Normalized();
        break;

    case TS_PARENT:
        parentSpacePoint = point;
        rotation = (delta * rotation).Normalized();
        break;

    case TS_WORLD:
        if (!parentNode)
        {
            parentSpacePoint = point;
            rotation = (delta * rotation).Normalized();
        }
        else
        {
            parentSpacePoint = parentNode->WorldTransform().Inverse() * point;
            Quaternion worldRotation = WorldRotation();
            rotation = rotation * worldRotation.Inverse() * delta * worldRotation;
        }
        break;
    }

    Vector3 oldRelativePos = oldRotation.Inverse() * (position - parentSpacePoint);
    position = rotation * oldRelativePos + parentSpacePoint;

    OnTransformChanged();
}
Exemplo n.º 22
0
		//----------------------------------------------------
		//----------------------------------------------------
		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;
		}
Exemplo n.º 23
0
 //----------------------------------------------------
 //----------------------------------------------------
 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;
 }
Exemplo n.º 24
0
void SpatialNode::SetDirection(const Vector3& newDirection)
{
    rotation = Quaternion(Vector3::FORWARD, newDirection);
    OnTransformChanged();
}
Exemplo n.º 25
0
void SpatialNode::SetRotation(const Quaternion& newRotation)
{
    rotation = newRotation;
    OnTransformChanged();
}
Exemplo n.º 26
0
void SpatialNode::OnParentSet(Node* newParent, Node*)
{
    SetFlag(NF_SPATIAL_PARENT, dynamic_cast<SpatialNode*>(newParent) != 0);
    OnTransformChanged();
}
Exemplo n.º 27
0
void SpatialNode::ApplyScale(const Vector3& delta)
{
    scale *= delta;
    OnTransformChanged();
}
Exemplo n.º 28
0
void SpatialNode::SetPosition(const Vector3& newPosition)
{
    position = newPosition;
    OnTransformChanged();
}
Exemplo n.º 29
0
 //-----------------------------------------------------------
 //-----------------------------------------------------------
 void SpriteComponent::SetTextureAtlas(const TextureAtlasCSPtr& in_atlas)
 {
     OnTransformChanged();
     
     m_textureAtlas = in_atlas;
 }
Exemplo n.º 30
0
		//----------------------------------------------------
		//----------------------------------------------------
		void SpriteComponent::OnAddedToScene()
		{
			m_transformChangedConnection = GetEntity()->GetTransform().GetTransformChangedEvent().OpenConnection(Core::MakeDelegate(this, &SpriteComponent::OnTransformChanged));
            
            OnTransformChanged();
		}