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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
|
/*
SABRE Fighter Plane Simulator
Copyright (c) 1997 Dan Hammer
Portions Donated By Antti Barck
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*************************************************
* SABRE Fighter Plane Simulator *
* Version: 0.1 *
* File : cpoly.h *
* Date : June, 1997 *
* Author : Dan Hammer *
* Classes for handling polygons, shapes and *
* some basic object definitions *
*************************************************/
#ifndef __cpoly_h
#define __cpoly_h
#ifndef __vmath_h
#include "vmath.h"
#endif
#ifndef __port_3d_h
#include "port_3d.h"
#endif
#include "target.h"
#ifndef __rendpoly_h
#include "rendpoly.h"
#endif
#ifndef __rndrpoly_h
#include "rndrpoly.h"
#endif
#include "clstypes.h"
/****************************************
* Bit-flag values used to set various *
* properties of polygons, shapes and *
* objects *
****************************************/
// C_Shape : Clip on minimum z-plane -
#define Z_CLIPME 1L
// C_Shape : Draw this shape first, don't sort by distance
#define ME_FIRST 2L
// C_Shape,C_Poly : Render cast shadow
#define SHADOW 4L
// C_Shape : I'm an important shape, don't drop me when
// doing distance abstraction
#define MAJOR_SHAPE 8L
// C_Poly : Intensity shade me
#define I_SHADE 1L
// C_3DObject : I'm a target
#define HIT_ME 1L
// C_Shape : copy poly #1's params to all others
#define CPY_PARAMS 16L
// C_Poly : texture map me
#define TXTR_MAP 2L
#define MAX_OBJECTS 512
inline int CheckPlaneEquation( const Vector &point,
const Vector &norm,
const REAL_TYPE pc)
{
REAL_TYPE dt1 = point.Dot(norm);
if (dt1 + pc >= 0)
return 0;
else
return 1;
}
inline REAL_TYPE Intensity( const Vector &light_source,
const Vector &norm)
{
REAL_TYPE val = light_source.Dot(norm ) + 1;
return (val / 2.0);
}
class poly_params
{
public:
int color;
unsigned long flags;
int color_range;
int tmap;
poly_params()
: color(0),
flags(0),
color_range(1),
tmap(-1)
{}
poly_params(int a_color,
unsigned long a_flag,
int a_color_range,
int a_tmap)
: color(a_color),
flags(a_flag),
color_range(a_color_range),
tmap(a_tmap)
{}
poly_params(const poly_params &pr)
{
copy(pr);
}
poly_params & operator=(const poly_params &pr)
{
copy(pr);
return(*this);
}
void copy(const poly_params &pr)
{
color = pr.color;
flags = pr.flags;
color_range = pr.color_range;
tmap = pr.tmap;
}
friend inline int operator ==(const poly_params & p1, const poly_params & p2);
void read(istream &);
void write(ostream &);
friend inline istream &operator >>(istream & is, poly_params &ps);
friend inline ostream &operator <<(ostream & os, poly_params &ps);
} ;
inline int operator ==(const poly_params &p1, const poly_params &p2)
{
return ((p1.color == p2.color) && (p1.flags == p2.flags)
&& (p1.color_range == p2.color_range)
&& (p1.tmap == p2.tmap));
}
inline istream &operator >>(istream &is, poly_params &ps)
{
ps.read(is);
return(is);
}
inline ostream &operator <<(ostream &os, poly_params &ps)
{
ps.write(os);
return(os);
}
class shape_params
{
public:
unsigned long flags;
poly_params *p_params;
int n_params;
shape_params()
: p_params(NULL),
n_params(0)
{}
shape_params(int n, unsigned long flgs, poly_params *pr)
: flags(flgs),
p_params(pr),
n_params(n)
{}
shape_params(const shape_params &sp)
{
p_params = NULL;
n_params = 0;
copy (sp);
}
shape_params &operator =(shape_params &sp)
{
copy (sp);
return (*this);
}
void copy (const shape_params &);
~shape_params()
{
if (p_params != NULL)
delete [] p_params;
}
void add(const poly_params &);
void read(istream &);
void write(ostream &);
friend inline istream & operator >>(istream &, shape_params &);
friend inline ostream & operator <<(ostream &, shape_params &);
} ;
inline istream & operator >>(istream &is, shape_params &sp)
{
sp.read(is);
return(is);
}
inline ostream & operator <<(ostream &os, shape_params &sp)
{
sp.write(os);
return(os);
}
class C_PolyInfo
{
public:
int npoints;
R_3DPoint *lpoints;
TxtPoint *tpoints;
int delete_flag;
bounding_cube bcube;
C_PolyInfo()
: npoints(0),
lpoints(NULL),
tpoints(NULL),
delete_flag(0)
{}
C_PolyInfo(int np, R_3DPoint *pnts, TxtPoint *tpnts = NULL)
:npoints(np),
lpoints(pnts),
tpoints(tpnts),
delete_flag(0)
{}
C_PolyInfo(const C_PolyInfo &cp)
{
lpoints = NULL;
tpoints = NULL;
copy (cp);
}
C_PolyInfo &operator =(const C_PolyInfo &cp)
{
copy(cp);
return(*this);
}
~C_PolyInfo()
{ if (lpoints && delete_flag) delete [] lpoints; }
C_PolyInfo &operator *=(REAL_TYPE scaler);
C_PolyInfo &operator +=(const R_3DPoint &p);
void copy(const C_PolyInfo &);
void read(istream &);
void write(ostream &);
friend inline istream &operator >>(istream &is, C_PolyInfo &cp);
friend inline ostream &operator <<(ostream &os, C_PolyInfo &cp);
};
inline istream &operator >>(istream &is, C_PolyInfo &cp)
{
cp.read(is);
return(is);
}
inline ostream &operator <<(ostream &os, C_PolyInfo &cp)
{
cp.write(os);
return(os);
}
class C_ShapeInfo
{
public:
int npolys;
C_PolyInfo *polyinfos;
int delete_flag;
bounding_cube bcube;
C_ShapeInfo()
: npolys(0),
polyinfos(NULL),
delete_flag(0)
{}
C_ShapeInfo(int np, C_PolyInfo *ip)
:npolys(np),
polyinfos(ip),
delete_flag(0)
{}
C_ShapeInfo(const C_ShapeInfo &cs)
{
polyinfos = NULL;
copy(cs);
}
C_ShapeInfo &operator =(const C_ShapeInfo &cs)
{
copy(cs);
return(*this);
}
~C_ShapeInfo()
{ if (delete_flag && polyinfos) delete [] polyinfos; }
C_ShapeInfo &operator *=(REAL_TYPE scaler);
C_ShapeInfo &operator +=(const R_3DPoint &p);
void copy(const C_ShapeInfo &);
void add(const C_PolyInfo &ip);
void read(istream &);
void write(ostream &);
friend inline istream &operator >>(istream &, C_ShapeInfo &);
friend inline ostream &operator <<(ostream &, C_ShapeInfo &);
};
inline istream &operator >>(istream &is, C_ShapeInfo &cp)
{
cp.read(is);
return(is);
}
inline ostream &operator <<(ostream &os, C_ShapeInfo &cp)
{
cp.write(os);
return(os);
}
extern C_ShapeInfo *shape_infos;
class C_3DObjectInfo
{
public:
C_ShapeInfo *shapes;
int nshapes;
shape_params *dflt_params;
bounding_cube bcube;
char *path;
char id[16];
C_3DObjectInfo()
:shapes(NULL),
nshapes(0),
dflt_params(NULL),
path(NULL)
{}
~C_3DObjectInfo()
{
if (shapes)
delete [] shapes;
if (dflt_params)
delete [] dflt_params;
if (path)
delete path;
}
void readFile(char *path);
void writeFile(char *path);
void read(istream &);
void write(ostream &);
friend inline istream &operator >>(istream &is, C_3DObjectInfo &co);
friend inline ostream &operator <<(ostream &os, C_3DObjectInfo &co);
};
inline istream &operator >>(istream &is, C_3DObjectInfo &co)
{
co.read(is);
return(is);
}
inline ostream &operator <<(ostream &os, C_3DObjectInfo &co)
{
co.write(os);
return(os);
}
class C_Poly
{
public:
int color,base_color;
int tmap;
unsigned long flags;
int color_range;
int visible;
REAL_TYPE scale;
C_PolyInfo *p_info;
R_3DPoint *wpoints;
R_3DPoint *zpoints;
Vector surface_normal;
REAL_TYPE plane_constant;
int shadow_flag;
static int txtrflag;
C_Poly();
virtual ~C_Poly();
virtual int create(C_PolyInfo *);
void compute_plane_constant(R_3DPoint &loc,
R_3DPoint *xpoints = NULL);
void set_world_points(R_3DPoint &loc);
void draw(Port_3D &theport, int = 1);
void render_shadow(Port_3D &theport, int z_clip,
REAL_TYPE z_value,
Vector &light_source,
int shadow_color);
void set_shadow(REAL_TYPE z_value, Vector &light_source);
void draw_shadow(Port_3D &theport, int z_clip, int shadow_color);
virtual void set_poly_icolor(Vector &);
friend istream &operator >>(istream &, C_Poly &);
void set_params(poly_params *prms);
void set_params(const C_Poly &);
virtual void set_scale(REAL_TYPE x)
{ scale = x; }
virtual void getBounds(bounding_cube &);
virtual void getWorldPoint(R_3DPoint &, int, R_3DPoint &);
int getScreenPoints(Port_3D &, R_2DPoint *spoints);
int getScreenPoints(Port_3D &, TR_2DPoint *spoints);
};
class C_Shape
{
public:
int npolys;
int visible;
unsigned long flags;
REAL_TYPE maxlen;
C_Poly *polys;
C_ShapeInfo *info_ptr;
C_Shape();
virtual ~C_Shape();
R_3DPoint location;
int memopt;
virtual int create(C_ShapeInfo *info_ptr);
virtual void set_poly_color(int n, int color);
virtual void set_world_location(R_3DPoint &);
virtual void set_visible(Port_3D &);
virtual void draw_shadow(Port_3D &);
virtual void set_shadow(REAL_TYPE , Vector &);
virtual void draw(Port_3D &, R_3DPoint &);
void set_poly_icolor(Vector &);
friend istream & operator >>(istream &, C_Shape &);
virtual void set_params(shape_params *);
virtual void set_scale(REAL_TYPE);
virtual void getBounds(bounding_cube &);
REAL_TYPE shadow_z;
Vector light_source;
};
#endif
|