Create Ground

Create Ground

Postby jaeyoung » 09 May 2009, 05:33

Picture 1.png
Ground
Picture 1.png (36.4 KiB) Viewed 132 times


Ground is one system. This has one link and one collision geometry basically.
Let's make a ground system class.

  • Declare ground class inheriting srSystem.
        class Ground: public srSystem
  • Declare one srLink and one srCollision for ground.
        public:
            srLink*      m_Ground;
            srCollision* m_Plane;

  • Declare constructor and destructor.
        public:
             Ground();
            ~Ground();

  • Declare a ground creating function, which returns a srSystem pointer.
        srSystem* BuildGround();
  • Define constructor and destructor.
        Ground::Ground()
        {
            m_Ground = new srLink;
            m_Plane = new srCollision;
        }

        Ground::~Ground()
        {
            delete m_Ground;
            delete m_Plane;
        }

  • Define BuildGround function.
    First, set m_Ground properties.
            m_Ground->GetGeomInfo().SetShape(srGeometry::PLANE);
            m_Ground->UpdateInertia();

    Every class derived from srEntity has a srGeometry member variable. Call srEntity::GetGeomInfo() function in order to get information about shape, color, dimension, etc.
    After setting the shape of srLink, you must call UpdateInertia(density) function. This function updates the mass and inertia of a link. The argument is density of a link. In case of a fixed link such as ground, since it is not important whether the mass and inertia values are exact, the density does not matter. (Default value is 1000 kg/m^3.)

    Next, set collision properties.
            m_Plane->GetGeomInfo().SetShape(srGeometryInfo::PLANE);
            m_Plane->SetLocalFrame(SE3());

    Make m_Plane have the same shape as m_Ground.
    SetLocalFrame() function sets the relative orientation and position of the center of srCollision with respect to the center of srLink to be connected with srCollision. (See this post http://r-station.co.kr/forum/viewtopic.php?f=7&t=13&start=0.)
    The argument SE3() makes the center of m_Plane identical to that of m_Ground.

    Add m_Plane to m_Ground.
            m_Ground->AddCollision(m_Plane);

    Finally, set srSystem properties.
            this->SetBaseLink(m_Ground);
            this->SetBaseLinkType(FIXED);

    Enroll m_Ground into Ground.
    Notify Ground that the base link is not moving.

How to use:
    srSpace gSpace;
    Ground gGround;
    gSpace.AddSystem(gGround.BuildGround());


Entire code is below.

header file: Ground.h
Code: Select all
#ifndef EXAMPLE_GROUND
#define EXAMPLE_GROUND

#include "srDyn/srSpace.h"

class Ground: public srSystem
{
public:
    srLink*      m_Ground;
    srCollision* m_Plane;

public:
              Ground();
             ~Ground();
    srSystem* BuildGround();
};
#endif //EXAMPLE_GROUND



source file: Ground.cpp
Code: Select all
#include "Ground.h"

Ground::Ground()
{
    m_Ground = new srLink;
    m_Plane = new srCollision;
}

Ground::~Ground()
{
    delete m_Ground;
    delete m_Plane;
}

srSystem* Ground::BuildGround()
{
    m_Ground->GetGeomInfo().SetShape(srGeometryInfo::PLANE);
    m_Ground->UpdateInertia();

    m_Plane->GetGeomInfo().SetShape(srGeometryInfo::PLANE);
    m_Plane->SetLocalFrame(SE3());

    m_Ground->AddCollision(m_Plane);

    this->SetBaseLink(m_Ground);
    this->SetBaseLinkType(FIXED);

    return this;
}

jaeyoung
 
Posts: 30
Joined: 07 Nov 2008, 08:39

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron