Klamp't  0.8.1
World.h
Go to the documentation of this file.
1 #ifndef ROBOT_WORLD_H
2 #define ROBOT_WORLD_H
3 
4 #include "Robot.h"
5 #include "Terrain.h"
6 #include "RigidObject.h"
7 #include <Klampt/View/ViewRobot.h>
8 #include <KrisLibrary/camera/camera.h>
9 #include <KrisLibrary/camera/viewport.h>
10 #include <KrisLibrary/GLdraw/GLLight.h>
11 
21 {
22  public:
23  typedef shared_ptr<Geometry::AnyCollisionGeometry3D> GeometryPtr;
24  typedef shared_ptr<GLDraw::GeometryAppearance> AppearancePtr;
25 
26  RobotWorld();
27  bool LoadXML(const char* fn);
28  bool SaveXML(const char* fn,const char* elementDir=NULL);
29  void InitCollisions();
30  void UpdateGeometry();
31  void SetGLLights();
32  void DrawGL();
33 
34  //integer id's for objects in the world
35  int NumIDs() const;
36  int GetID(const string& name,int link=-1) const;
37  string GetName(int id) const;
39  int IsTerrain(int id) const;
41  int IsRigidObject(int id) const;
43  int IsRobot(int id) const;
45  pair<int,int> IsRobotLink(int id) const;
46  int TerrainID(int index) const;
47  int RigidObjectID(int index) const;
48  int RobotID(int index) const;
49  int RobotLinkID(int index,int link) const;
50  GeometryPtr GetGeometry(int id);
51  AppearancePtr GetAppearance(int id);
52  RigidTransform GetTransform(int id) const;
53  void SetTransform(int id,const RigidTransform& T);
54 
55  int LoadRobot(const string& fn);
56  int AddRobot(const string& name,Robot* robot=NULL);
57  void DeleteRobot(const string& name);
58  Robot* GetRobot(const string& name);
59  ViewRobot* GetRobotView(const string& name);
60 
61  int LoadTerrain(const string& fn);
62  int AddTerrain(const string& name,Terrain* terrain=NULL);
63  void DeleteTerrain(const string& name);
64  Terrain* GetTerrain(const string& name);
65 
66  int LoadRigidObject(const string& fn);
67  int AddRigidObject(const string& name,RigidObject* obj=NULL);
68  void DeleteRigidObject(const string& name);
69  RigidObject* GetRigidObject(const string& name);
70 
72  int RayCast(const Ray3D& r,Vector3& worldpt);
73  Robot* RayCastRobot(const Ray3D& r,int& body,Vector3& localpt);
74  RigidObject* RayCastObject(const Ray3D& r,Vector3& localpt);
75 
78  int LoadElement(const string& fn);
80  bool CanLoadElementExt(const char* ext) const;
81 
82  //viewport info
83  Camera::Camera camera;
84  Camera::Viewport viewport;
85  vector<GLDraw::GLLight> lights;
86  GLDraw::GLColor background;
87 
88  //world occupants
89  vector<shared_ptr<Robot> > robots;
90  vector<shared_ptr<Terrain> > terrains;
91  vector<shared_ptr<RigidObject> > rigidObjects;
92 
93  vector<ViewRobot> robotViews;
94 };
95 
100 void CopyWorld(const RobotWorld& a,RobotWorld& b);
101 
102 #endif
The main robot type used in RobotSim.
Definition: Robot.h:79
void CopyWorld(const RobotWorld &a, RobotWorld &b)
Performs a shallow copy of a RobotWorld. Since it does not copy geometry, this operation is very fast...
bool CanLoadElementExt(const char *ext) const
Returns true if the given extension is loadable as an element.
The main world class containing multiple robots, objects, and static geometries (terrains). Lights and other viewport information may also be stored here.
Definition: World.h:20
Draws the robot (potentially color-coded)
Definition: ViewRobot.h:12
int LoadElement(const string &fn)
A model of a static terrain with known friction.
Definition: Terrain.h:13
pair< int, int > IsRobotLink(int id) const
Returns the index of the robot link or -1,-1 otherwise.
int IsRobot(int id) const
Returns the index of the robot or -1 otherwise.
int IsRigidObject(int id) const
Returns the index of the rigid object or -1 otherwise.
int IsTerrain(int id) const
Returns the index of the terrain or -1 otherwise.
int RayCast(const Ray3D &r, Vector3 &worldpt)
Returns the ID of the entity the ray hits, or -1 if nothing was hit.
A (static) rigid object that may be manipulated.
Definition: RigidObject.h:13