vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KeepOnScreen.h
Go to the documentation of this file.
1 #ifndef KEEPONSCREEN_H
2 #define KEEPONSCREEN_H
3 
4 #include <vrecko/Ability.h>
5 
6 using namespace vrecko;
7 
8 namespace APObjectUtils
9 {
10 
11  #define HORIZ_ALIGN_OUTER -100000.0f
12  // Means "Align to the outer edge of the bounding box"
13  #define VERT_ALIGN_OUTER -100000.0f
14  // Means "Align to the outer edge of the bounding box"
15 
16 
17  /* Parameters can be specified in the following way:
18 
19  <Ability Priority="-100">
20  // It's NECESARY to lower the priority so camera movements are
21  // performed BEFORE calculating the proper position of the dependend objects
22 
23  <Name>KeepOnScreen</Name>
24  <PluginName>ObjectUtils</PluginName>
25 
26 
27  <Parameters>
28  <Position>1.0 1.0</Position>
29  // Alignment point ON THE SCREEN.
30  // First number: -1.0 ... 1.0 is for left to right edge
31  // Second number: -1.0 ... 1.0 is for bottom to top edge
32 
33  <HorizAlign>outer</HorizAlign>
34  // Alignment point ON THE BOUNDING BOX of the object
35  // Can be either number (-1.0 ... 1.0 for left to right edge of the BB)
36  // or the word "outer", which means the other edge (is taken
37  // automatically according to the <Position> settings)
38 
39  <VertAlign>outer</VertAlign>
40  // Same as <Horizalign>, but for bottom to top edges
41 
42  <Scale>0.1</Scale>
43  // Scaling of the object. The scale is set for an object in distance 1.0.
44  // Should the object be in any other distance from the camera, the scaling
45  // is automatically adjusted to maintain same size.
46 
47  <Depth>1.0</Depth>
48  // Depth from the viewer. If lower than near plane, than the object
49  // is shifted away from the viewer and placed on the near plane.
50  // (Efectivelly - you could set it to 0 and let the system place the object
51  // as near as possible. UNFORTUNATELY, due to some problem, the near planes
52  // are sometimes changed from frame to frame and the object could be chopped
53  // in two.)
54 
55 
56  <RelativeToBoundingBox>false</RelativeToBoundingBox>
57  // ("true" is the default value)
58  // If "false" then vertAlign/horizAlign values are absolute shifts and not
59  // multiplications relative to the bounding box.
60 
61  <DontRotate>true</DontRotate>
62  // ("false" is the default value)
63  // If "true" then the object will be kept static relatively to the camera.
64 
65  </Parameters>
66 
67 
68  </Ability>
69 
70  */
71 
72 
73 
74  class KeepOnScreen: public Ability
75  {
76  public:
77  KeepOnScreen();
78  virtual ~KeepOnScreen();
79 
80  virtual void preInitialize();
81  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *pParametersNode);
82  virtual void update();
83  virtual void clean();
84  protected:
86 
87  float posX, posY; // 2D position on the screen
88  float depth; // similar to z-depth (may not be 100 % precise)
89 
91  // Is the alignment relative to the bounding box OR to is it only shift relative to
92  // the object's center?
93 
94  float horizAlign; // alignment of the object's bounding box OR left/right shift.
95  // (-1.0 means to the left, 0.0 is center, 1.0 is to the right)
96  // HORIZ_ALIGN_OUTER means "outer edge" of the bounding box
97  float vertAlign; // alignment of the object's bounding box OR top/bottom.
98  // (-1.0 means to the bottom, 0.0 is center, 1.0 is to the top)
99  // VERT_ALIGN_OUTER means "outer edge" of the bounding box
100  float scale; // Scaling (1.0 = no scaling)
101  bool bDontRotate; // true => keep original rotation, so the object is not static
102  // relative to camera
103 
104  };
105 
106 }
107 
108 #endif