Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
gameobject.hpp
1 //////////////////////////////
2 //
3 // File: lxs/game/gameobject.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Feb 27 2013
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_GAME_OBJECT__
15 #define __LXS_GAME_OBJECT__
16 #include <boost/shared_ptr.hpp>
17 #include <string>
18 #include <map>
19 #include "lxs/coregraphics/p_model.hpp"
20 #include "lxs/coregraphics/primitives.hpp"
21 namespace LxS
22 {
23  namespace CoreGraphics
24  {
25  class Model;
26  class Renderable;
27  class LineSegment;
28  }
29  namespace Game
30  {
31  //! animation sequence
32  class Sequence
33  {
34  public:
35  //! speed in fps
36  float spf;
37  //! first frame (of model frames)
39  //! last frame
41  //! loop or play once
42  bool loop;
43  };
44  class Map;
45  //! Three dimensional interactive game object that is not a character (typically just a decoration considered by renderer and collision detection system)
47  {
48  protected:
49  //! pointer to a model
50  boost::shared_ptr<LxS::CoreGraphics::Model> p_Model;
51  //! filename
52  std::string object_fn;
53  //! sequence name, firstxo frame, last frame
54  typedef std::map< std::string, Sequence > AnimationMap;
55  //! all animation sequences supported
57  //! current animation sequence that is played
58  AnimationMap::iterator current_sequence;
59  //! animation frame
61  //! map containing this
63  //! set greater than 1 if want to accelerate animation;
65  public:
66  //! return model of an item (only if it has a graphical representation)
68  //! a valid Map object must be given in a constructor
71  //! set name of file describing this particular game object (its models, textures, animation sequences etc)
72  void SetFilename(std::string fn) { object_fn=fn;}
73  //!return filename
74  const std::string GetFilename() {return object_fn;}
75  //! select animation sequences to be played
76  virtual void SelectAnimation(std::string seq_name);
77  //! select area alongside which character is allowed to move
79  //! rotate around axis, that is perpendicular to the ground
80  virtual void SetRotationY(float alpha);
81  //! for deserialization, status query etc.
82  virtual float GetRotationY();
83  virtual void Animate(float dt);
84  //! set coordinates of game object in 3D space (its own 0/0/0 point is moved against global 0/0/0)
85  virtual void SetPosition(float x, float y, float z);
86  //! where it is (note, that this may be inaccurate if more than one gameobject is represented by the same model mesh; TODO: fix GetPositionX/Y/Z in GameObject)
87  virtual float GetPositionX();
88  //! where it is
89  virtual float GetPositionY();
90  //! where it is
91  virtual float GetPositionZ();
92  virtual void Initialize(); // load and set up some resources
93  virtual void Render(Rendermode mode);
94  virtual void RefreshAssets() ;
95  virtual void UnloadResources();
96  unsigned long GetTexelsCount();
97  unsigned long GetFacesCount();
98 
99  //! does object cb in pos x,y,z cause collision with THIS?
100  virtual bool CollisionDetection(GameObject * cb, float x, float y, float z);
101 
102  };
103  }
104 }
105 #endif