File: SceneNode.h

package info (click to toggle)
bzflag 2.0.2.20050318
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 20,464 kB
  • ctags: 24,134
  • sloc: cpp: 110,038; ansic: 9,514; sh: 4,105; makefile: 1,922; perl: 280; python: 221; xml: 180; objc: 178; php: 143
file content (230 lines) | stat: -rw-r--r-- 6,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* bzflag
 * Copyright (c) 1993 - 2005 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/* SceneNode:
 *	Encapsulates information for rendering an object in the scene.
 *
 * GLfloat2
 * GLfloat3
 *	Arrays of two and three GLfloat's
 *
 * GLfloat2Array
 * GLfloat3Array
 *	Arrays of GLfloat2's and GLfloat3's
 *
 * Probably shouldn't use names like this (GLfloat...).  Oh well.
 */

#ifndef	BZF_SCENE_NODE_H
#define	BZF_SCENE_NODE_H

#include "common.h"
#include "bzfgl.h"
#include "bzfio.h"
#include "OpenGLGState.h"
#include "RenderNode.h"
#include "Extents.h"

#if !defined(_WIN32)
// bonehead win32 cruft.  just make it go away on other platforms.
#ifdef __stdcall
#undef __stdcall
#endif
#define	__stdcall
#endif

#define	myColor3f(r, g, b)	SceneNode::glColor3f(r, g, b)
#define	myColor4f(r, g, b, a)	SceneNode::glColor4f(r, g, b, a)
#define	myColor3fv(rgb)		SceneNode::glColor3fv(rgb)
#define	myColor4fv(rgba)	SceneNode::glColor4fv(rgba)
#define	myStipple(alpha)	SceneNode::setStipple(alpha)

class ViewFrustum;
class SceneRenderer;

class SceneNode {
  public:
			SceneNode();
    virtual		~SceneNode();

    const GLfloat*	getSphere() const;
    const Extents&	getExtents() const;
    virtual bool	inAxisBox (const Extents& exts) const;
    virtual int		getVertexCount () const;
    virtual const GLfloat* getVertex (int vertex) const;
    virtual bool	isTranslucent() const;
    virtual void	notifyStyleChange();

    const GLfloat*      getPlane() const;
    const GLfloat*      getPlaneRaw() const;
    virtual GLfloat	getDistance(const GLfloat* eye) const;
    virtual bool	cull(const ViewFrustum&) const;
    virtual void	addLight(SceneRenderer&);
    virtual int		split(const float* plane,
				SceneNode*& front, SceneNode*& back) const;
    virtual void	addShadowNodes(SceneRenderer&);
    virtual void	addRenderNodes(SceneRenderer&);

    virtual int getRenderNodeCount() { return 0; }
    virtual RenderNode*	getRenderNode(int) { return NULL; }
    virtual const OpenGLGState* getGState() const { return NULL; }


    static void		setColorOverride(bool = true);
    static void		glColor3f(GLfloat r, GLfloat g, GLfloat b)
#ifdef __MINGW32__
      {if (!colorOverride) ::glColor3f(r, g, b); };
#else
      { (*color3f)(r, g, b); }
#endif

    static void		glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
#ifdef __MINGW32__
      {if (!colorOverride) ::glColor4f(r, g, b, a); };
#else
      { (*color4f)(r, g, b, a); }
#endif

    static void		glColor3fv(const GLfloat* rgb)
#ifdef __MINGW32__
      {if (!colorOverride) ::glColor3fv(rgb); };
#else
      { (*color3fv)(rgb); }
#endif

    static void		glColor4fv(const GLfloat* rgba)
#ifdef __MINGW32__
      {if (!colorOverride) ::glColor4fv(rgba); };
#else
      { (*color4fv)(rgba); }
#endif

    static void		setStipple(GLfloat alpha) { (*stipple)(alpha); }

    enum CullState {
      OctreeCulled,
      OctreePartial,
      OctreeVisible
    };

    /** This boolean is used by the Octree code.
	Someone else can 'friend'ify it later.
    */
    CullState octreeState;

  protected:
    void		setRadius(GLfloat radiusSquared);
    void		setCenter(const GLfloat center[3]);
    void		setCenter(GLfloat x, GLfloat y, GLfloat z);
    void		setSphere(const GLfloat sphere[4]);

  private:
			SceneNode(const SceneNode&);
    SceneNode&		operator=(const SceneNode&);



#ifndef __MINGW32__
    static void __stdcall	noColor3f(GLfloat, GLfloat, GLfloat);
    static void __stdcall	noColor4f(GLfloat, GLfloat, GLfloat, GLfloat);
    static void __stdcall	noColor3fv(const GLfloat*);
    static void __stdcall	noColor4fv(const GLfloat*);
#endif
    static void			noStipple(GLfloat);

  protected:
    GLfloat		plane[4];	// unit normal, distance to origin
    bool		noPlane;
    Extents		extents;
  private:
    GLfloat		sphere[4];
#ifdef __MINGW32__
    static bool	 colorOverride;
#else
    static void		(__stdcall *color3f)(GLfloat, GLfloat, GLfloat);
    static void		(__stdcall *color4f)(GLfloat, GLfloat, GLfloat, GLfloat);
    static void		(__stdcall *color3fv)(const GLfloat*);
    static void		(__stdcall *color4fv)(const GLfloat*);
#endif
    static void		(*stipple)(GLfloat);
};

inline const GLfloat*   SceneNode::getPlane() const
{
  if (noPlane)
    return NULL;
  return plane;
}

inline const GLfloat*   SceneNode::getPlaneRaw() const
{
  return plane;
}

inline const GLfloat*	SceneNode::getSphere() const
{
  return sphere;
}

inline const Extents&	SceneNode::getExtents() const
{
  return extents;
}


typedef GLfloat		GLfloat2[2];
typedef GLfloat		GLfloat3[3];

class GLfloat2Array {
  public:
			GLfloat2Array(int s) : size(s)
				{ data = new GLfloat2[size]; }
			GLfloat2Array(const GLfloat2Array&);
			~GLfloat2Array() { delete[] data; }
    GLfloat2Array&	operator=(const GLfloat2Array&);
    GLfloat*		operator[](int i) { return data[i]; }
    const GLfloat*	operator[](int i) const { return data[i]; }
    int			getSize() const { return size; }
    const GLfloat2*	getArray() const { return data; }

  private:
    int			size;
    GLfloat2*		data;
};

class GLfloat3Array {
  public:
			GLfloat3Array(int s) : size(s)
				{ data = new GLfloat3[size]; }
			GLfloat3Array(const GLfloat3Array&);
			~GLfloat3Array() { delete[] data; }
    GLfloat3Array&	operator=(const GLfloat3Array&);
    GLfloat*		operator[](int i) { return data[i]; }
    const GLfloat*	operator[](int i) const { return data[i]; }
    int			getSize() const { return size; }
    const GLfloat3*	getArray() const { return data; }

  private:
    int			size;
    GLfloat3*		data;
};

#endif // BZF_SCENE_NODE_H

// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8