Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Graphic.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright (C) 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: nGenEx.lib
6  FILE: Graphic.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Abstract 3D Graphic Object
13 */
14 
15 #ifndef Graphic_h
16 #define Graphic_h
17 
18 #include "Geometry.h"
19 #include "Color.h"
20 #include "List.h"
21 
22 // +--------------------------------------------------------------------+
23 
24 #define GRAPHIC_DESTROY(x) if (x) { x->Destroy(); x = 0; } //-V571
25 
26 // +--------------------------------------------------------------------+
27 
28 class Projector;
29 class Light;
30 class Scene;
31 class Video;
32 
33 // +--------------------------------------------------------------------+
34 
35 class Graphic
36 {
37 public:
38  static const char* TYPENAME() { return "Graphic"; }
39 
40  enum TYPE { OTHER, SOLID, SPRITE, BOLT, QUAD };
41 
42  enum RENDER_FLAGS {
43  RENDER_SOLID = 0x0001,
44  RENDER_ALPHA = 0x0002,
45  RENDER_ADDITIVE = 0x0004,
48  };
49 
50  Graphic();
51  virtual ~Graphic();
52 
53  int operator == (const Graphic& g) const { return id == g.id; }
54  int operator < (const Graphic& g) const;
55  int operator <= (const Graphic& g) const;
56 
57  // operations
58  virtual void Render(Video* video, DWORD flags) { }
59  virtual void Update() { }
60  virtual void SetOrientation(const Matrix& o) { }
61 
62  virtual int CollidesWith(Graphic& o);
63 
64  // accessors / mutators
65  int Identity() const { return id; }
66  const char* Name() const { return name; }
67  bool IsVisible() const { return visible; }
68  void SetVisible(bool v) { visible = v; }
69  float Radius() const { return radius; }
70 
71  Point Location() const { return loc; }
72  virtual void MoveTo(const Point& p) { loc = p; }
73  virtual void TranslateBy(const Point& ref) { loc = loc - ref; }
74 
75  virtual float Depth() const { return depth; }
76  virtual void SetDepth(float d) { depth = d; }
77  static int Nearer(Graphic* a, Graphic* b);
78  static int Farther(Graphic* a, Graphic* b);
79 
80  virtual int IsInfinite() const { return infinite; }
81  virtual void SetInfinite(bool b);
82  virtual int IsForeground() const { return foreground; }
83  virtual void SetForeground(bool f){ foreground = f; }
84  virtual int IsBackground() const { return background; }
85  virtual void SetBackground(bool b){ background = b; }
86 
87  virtual int Hidden() const { return hidden; }
88  virtual int Life() const { return life; }
89  virtual void Destroy();
90  virtual void Hide() { hidden = true; }
91  virtual void Show() { hidden = false; }
92  virtual bool Luminous() const { return luminous;}
93  virtual void SetLuminous(bool l) { luminous = l; }
94  virtual bool Translucent() const { return trans; }
95  virtual bool CastsShadow() const { return shadow; }
96  virtual void SetShadow(bool s) { shadow = s; }
97 
98  virtual bool IsSolid() const { return false; }
99  virtual bool IsSprite() const { return false; }
100  virtual bool IsBolt() const { return false; }
101  virtual bool IsQuad() const { return false; }
102 
103  virtual void ProjectScreenRect(Projector* p);
104  const Rect& ScreenRect() const { return screen_rect; }
105  virtual Scene* GetScene() const { return scene; }
106  virtual void SetScene(Scene*s) { scene = s; }
107 
108  virtual int CheckRayIntersection(Point pt, Point vpn, double len, Point& ipt,
109  bool treat_translucent_polys_as_solid=true);
110 
111  virtual bool CheckVisibility(Projector& projector);
112 
113 protected:
114  static int id_key;
115 
116  int id;
118  float depth;
119  float radius;
120  int life;
121 
122  bool visible;
123  bool infinite;
126  bool hidden;
127  bool trans;
128  bool shadow;
129  bool luminous;
130 
133  char name[32];
134 };
135 
136 // +--------------------------------------------------------------------+
137 
138 #endif Graphic_h
139