[go: up one dir, main page]

File: copoly.h

package info (click to toggle)
sabre 0.2.3-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 4,876 kB
  • ctags: 5,106
  • sloc: cpp: 25,581; ansic: 7,439; sh: 2,063; makefile: 92
file content (111 lines) | stat: -rw-r--r-- 3,394 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
/*
    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   : copoly.h                             *
 * Date   : March, 1997                          *
 * Author : Dan Hammer                           *
 * "Oriented Poly" class. Polygons and shapes    *
 * which are defined in "port coordinants" so    *
 * that they can be translated and rotated.      *
 * To draw them, you need a "reference port"     *
 * which transforms them into world coordinants. *
 *************************************************/
#ifndef __copoly_h
#define __copoly_h

#ifndef __cpoly_h
#include "cpoly.h"
#endif

inline int O_CheckPlaneEquation(const Vector &point,
				const Vector &normal,
				const REAL_TYPE p_const)
{
  float dt1 = point.Dot(normal);
  if (dt1 + p_const >= 0)
    return 1;
  else
    return 0;
}

inline float O_Intensity( const Vector &light_source,
			  const Vector &normal)
{
  float val = light_source.Dot(normal) + 1.0;
  return (val / 2.0);
}

class C_Oriented_Poly : public C_Poly
{
public:
  // This member also allows scaling
  static REAL_TYPE co_scaler;
  C_Oriented_Poly();
  ~C_Oriented_Poly();
  int create(C_PolyInfo *);
  void set_world_points(Port_3D &);
  void set_poly_icolor(Vector &);
  void create_points(Port_3D &ref_port);
  void render_shadow(Port_3D &theport, int z_clip,
		     REAL_TYPE z_value,
		     Vector &light_source,
		     int shadow_color,
		     Port_3D &ref_port);
  void draw(Port_3D &theport, Port_3D &ref_port, int = 1);
  friend ostream & operator <<(ostream &, C_Oriented_Poly &);
  void write(ostream &os);
  int getScreenPoints(Port_3D &, Port_3D &, R_2DPoint *spoints);
  int getScreenPoints(Port_3D &, Port_3D &, TR_2DPoint *spoints);

};

inline void set_co_scaler(REAL_TYPE sc)
{
  C_Oriented_Poly::co_scaler = sc;
}

class C_Oriented_Shape : public C_Shape
{
public:
  C_Oriented_Poly *o_polys;
  Port_3D *ref_port;

  C_Oriented_Shape();
  ~C_Oriented_Shape();
  int create(C_ShapeInfo *info_ptr);
  void set_world_location(R_3DPoint &)
    { }
  void set_visible(Port_3D &);
  void draw(Port_3D &, R_3DPoint &);
  void render_shadow(Port_3D &, Vector &);
  void set_world_points(Port_3D &);
  void set_poly_icolor(Vector &light);
  void set_poly_color(int n, int color);
  int drawn_flag;
  friend istream &operator >>(istream &, C_Oriented_Shape &);
  void set_params(shape_params *);
  friend ostream &operator <<(ostream &, C_Oriented_Shape &);
  void create_points(Port_3D &ref_port);
  void delete_points();
};

#endif