wheeledexperimenthelper.h
1 /********************************************************************************
2  * FARSA Experimentes Library *
3  * Copyright (C) 2007-2012 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
21  ********************************************************************************/
22 
23 #ifndef WHEELEDEXPERIMENTHELPER_H
24 #define WHEELEDEXPERIMENTHELPER_H
25 
26 #include "experimentsconfig.h"
27 #include "parametersettable.h"
28 #include "resourcesuser.h"
29 #include "world.h"
30 #include "wvector.h"
31 #include "phyobject.h"
32 #include "phybox.h"
33 #include "phycylinder.h"
34 #include <QVector>
35 
36 namespace farsa {
37 
38 class Arena;
39 class RobotOnPlane;
40 class WheeledRobot2DWrapper;
41 
50 class FARSA_EXPERIMENTS_API PhyObject2DWrapper
51 {
52 public:
56  enum Type {
57  Plane = 0,
58  Wall,
59  Box,
60  RectangularTargetArea,
61  Cylinder,
62  SmallCylinder,
63  BigCylinder,
64  CircularTargetArea,
65  WheeledRobot,
66  NumberOfDifferentTypes
67  };
68 
69 public:
78  virtual WObject* wObject();
79 
86  virtual const WObject* wObject() const;
87 
96  virtual PhyObject* phyObject() = 0;
97 
105  virtual const PhyObject* phyObject() const = 0;
106 
113  virtual Type type() const = 0;
114 
123  virtual void setStatic(bool s);
124 
133  bool getStatic() const;
134 
141  void setPosition(wVector pos);
142 
150  virtual void setPosition(real x, real y) = 0;
151 
157  wVector position() const;
158 
180  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& mtr, double& minAngle, double& maxAngle, double& distance) const = 0;
181 
196  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const = 0;
197 
203  void setTexture(QString textureName);
204 
210  QString texture() const;
211 
217  void setColor(QColor color);
218 
224  QColor color() const;
225 
233  void setUseColorTextureOfOwner(bool b);
234 
242  bool useColorTextureOfOwner() const;
243 
244 protected:
250  PhyObject2DWrapper(Arena* arena);
251 
255  virtual ~PhyObject2DWrapper();
256 
260  Arena *const m_arena;
261 
262 private:
269 
275  PhyObject2DWrapper& operator=(const PhyObject2DWrapper&);
276 
281  friend class Arena;
282 };
283 
287 class FARSA_EXPERIMENTS_API Box2DWrapper : public PhyObject2DWrapper
288 {
289 public:
297  virtual PhyBox* phyObject();
298 
304  virtual const PhyBox* phyObject() const;
305 
311  virtual Type type() const;
312 
319  virtual void setStatic(bool s);
320 
328  virtual void setPosition(real x, real y);
329 
354  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& cameraMtr, double& minAngle, double& maxAngle, double& distance) const;
355 
370  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const;
371 
380  const wVector& vertex(int i) const
381  {
382  return m_vertexes[i];
383  }
384 
392  const wVector& centerOnPlane() const
393  {
394  return m_centerOnPlane;
395  }
396 
397 protected:
408  Box2DWrapper(Arena* arena, PhyBox* box, Type type);
409 
413  ~Box2DWrapper();
414 
415 private:
419  PhyBox* const m_box;
420 
427  QVector<wVector> m_vertexes;
428 
434  wVector m_centerOnPlane;
435 
443  const Type m_type;
444 
449  friend class Arena;
450 };
451 
455 class FARSA_EXPERIMENTS_API Cylinder2DWrapper : public PhyObject2DWrapper
456 {
457 public:
465  virtual PhyCylinder* phyObject();
466 
472  virtual const PhyCylinder* phyObject() const;
473 
481  virtual void setStatic(bool s);
482 
488  virtual Type type() const;
489 
496  virtual void setPosition(real x, real y);
497 
522  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& cameraMtr, double& minAngle, double& maxAngle, double& distance) const;
523 
538  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const;
539 
540 protected:
551  Cylinder2DWrapper(Arena* arena, PhyCylinder* cylinder, Type type);
552 
557 
558 private:
562  PhyCylinder* const m_cylinder;
563 
571  const Type m_type;
572 
577  friend class Arena;
578 };
579 
583 class FARSA_EXPERIMENTS_API WheeledRobot2DWrapper : public PhyObject2DWrapper
584 {
585 public:
586 
594  RobotOnPlane* robotOnPlane();
595 
602  const RobotOnPlane* robotOnPlane() const;
603 
611  virtual WObject* wObject();
612 
618  virtual const WObject* wObject() const;
619 
626  virtual PhyObject* phyObject();
627 
634  virtual const PhyObject* phyObject() const;
635 
641  virtual Type type() const;
642 
649  virtual void setPosition(real x, real y);
650 
675  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& cameraMtr, double& minAngle, double& maxAngle, double& distance) const;
676 
691  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const;
692 
698  double getHeight() const
699  {
700  return m_height;
701  }
702 
708  double getRadius() const
709  {
710  return m_radius;
711  }
712 
718  void storePreviousMatrix()
719  {
720  m_previousMatrix = wObject()->matrix();
721  }
722 
728  const wMatrix& previousMatrix() const
729  {
730  return m_previousMatrix;
731  }
732 
733 protected:
742  WheeledRobot2DWrapper(Arena* arena, RobotOnPlane* robot, double height, double radius);
743 
748 
749 private:
753  RobotOnPlane* const m_robot;
754 
758  const double m_height;
759 
763  const double m_radius;
764 
771  wMatrix m_previousMatrix;
772 
777  friend class Arena;
778 };
779 
780 
792 wVector FARSA_EXPERIMENTS_API positionOnPlane(const Box2DWrapper* plane, real x, real y);
793 
809 void FARSA_EXPERIMENTS_API orientationOnPlane(const Box2DWrapper* plane, real angle, wMatrix& mtr);
810 
822 real FARSA_EXPERIMENTS_API angleBetweenXAxes(const wMatrix& mtr1, const wMatrix& mtr2);
823 
824 } // end namespace farsa
825 
826 #endif