コード例 #1
0
 void PhysicsObject::Update(double aDelta)
 {
     //If this assert is hit, it means the physics body is null
     assert(m_PhysicsBody != nullptr);
     
     //If there is a physics update, make sure to awaken the physics body
     if(m_UpdateFlags != PhysicsUpdateNone)
     {
         m_PhysicsBody->SetAwake(true);
     }
     
     //Is the update transform bit set?
     if((m_UpdateFlags & PhysicsUpdateTransform) > 0)
     {
         //Turn the transform bit off
         m_UpdateFlags &= ~PhysicsUpdateTransform;
         
         //Convert the position from pixels into meters
         b2Vec2 position = b2Helper::PixelsToMeters(m_Position.x, m_Position.y);
         
         //Convert the angle from degrees into radians
         float angle = m_Angle * TO_RADIANS;
     
         //Set the physics body's transform
         m_PhysicsBody->SetTransform(position, angle);
     }
     
     //Is the update active bit set?
     if((m_UpdateFlags & PhysicsUpdateActive) > 0)
     {
         //Turn the active bit off
         m_UpdateFlags &= PhysicsUpdateActive;
         
         //Set the physics body active flag
         m_PhysicsBody->SetActive(m_IsEnabled);
     }
     
     //Is the update body type bit set?
     if((m_UpdateFlags & PhysicsUpdateBodyType) > 0)
     {
         //Turn the body type bit off
         m_UpdateFlags &= PhysicsUpdateBodyType;
         
         //Set the physics body type
         m_PhysicsBody->SetType(m_BodyType);
     }
     
     //Reset the model matrix, this ensure the game object and its children are drawn at the same location as the box2d body
     ResetModelMatrix();
 
     //Update the base object
     GameObject::Update(aDelta);
 }
コード例 #2
0
 void Label::Draw()
 {
     //If this assert is hit, it means there isn't a Shader set
     assert(m_Shader != nullptr);
 
     //Is the model matrix dirty?
     if(IsModelMatrixDirty() == true)
     {
         ResetModelMatrix();
     }
 
     //Is the render target null
     if(m_RenderTarget != nullptr)
     {
         //Draw the render target
         m_RenderTarget->GetTextureFrame()->Draw(m_ModelMatrix);
     }
     else
     {
         //Draw the text with out the render target
         DrawText();
     }
     
     //Draw a debug label rect
     #if DRAW_LABEL_RECT
     Rect rect(GetWorldPosition().x, GetWorldPosition().y, GetWidth(), GetHeight());
     rect.SetIsFilled(false);
     rect.SetColor(DRAW_LABEL_RECT_COLOR);
     rect.SetAnchorPoint(GetAnchorPoint());
     rect.SetLocalAngle(GetWorldAngle());
     rect.SetLocalScale(GetWorldScale());
     rect.Draw();
     #endif
     
     //Draw the GameObject, which draws all the children
     GameObject::Draw();
 }
コード例 #3
0
    void Polygon::Draw()
    {
        //Safety check the shader
        if(m_Shader == nullptr)
        {
            return;
        }
        
        //If the model matrix is dirty, reset it
        if(IsModelMatrixDirty() == true)
        {
            ResetModelMatrix();
        }
    
        //Use the shader
        m_Shader->Use();
        
        //Set the point size attribute
        int pointSizeIndex = m_Shader->GetAttribute("a_pointSize");
        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
        glVertexAttrib1f(pointSizeIndex, m_PointSize);
        
        //Cache the graphics service
        Graphics* graphics = ServiceLocator::GetGraphics();
    
        //Bind the vertex array object
        graphics->BindVertexArray(m_VertexArrayObject);

        //Set the model view projection matrix
        mat4 mvp = graphics->GetProjectionMatrix() * graphics->GetViewMatrix() * m_ModelMatrix;
        glUniformMatrix4fv(m_Shader->GetModelViewProjectionUniform(), 1, 0, &mvp[0][0]);
        
        //Validate the shader
        if(m_Shader->Validate() == false)
        {
            Error(false, "Can't draw Polygon, shader failed to validate");
            return;
        }
        
        //Disable blending, if we did in fact have it enabled
        if(m_Color.Alpha() != 1.0f)
        {
            graphics->EnableBlending();
        }
        
        //Render the polygon
        glDrawArrays(m_RenderMode, 0, (GLsizei)m_Vertices.size());
        
        //Disable blending, if we did in fact have it enabled
        if(m_Color.Alpha() != 1.0f)
        {
            graphics->DisableBlending();
        }
        
        //Unbind the vertex array
        ServiceLocator::GetGraphics()->BindVertexArray(0);
        
        //Draw the debug anchor point
        #if DRAW_POLYGON_ANCHOR_POINT
        if(GetType() != "Point" && GetType() != "Line")
        {
            Line lineA(m_AnchorLocation, vec2(m_AnchorLocation.x, m_AnchorLocation.y + DRAW_POLYGON_ANCHOR_POINT_SIZE));
            lineA.SetLocalAngle(GetWorldAngle());
            lineA.SetColor(Color::RedColor());
            lineA.Draw();
        
            Line lineB(m_AnchorLocation, vec2(m_AnchorLocation.x + DRAW_POLYGON_ANCHOR_POINT_SIZE, m_AnchorLocation.y));
            lineB.SetLocalAngle(GetWorldAngle());
            lineB.SetColor(Color::GreenColor());
            lineB.Draw();
        }
        #endif
        
        //Call the GameObject's Draw() method, this will ensure that any children will also get drawn
        GameObject::Draw();
    }