FS2_Open
Open source remastering of the Freespace 2 engine
3ddraw.cpp File Reference
#include "bmpman/bmpman.h"
#include "cmdline/cmdline.h"
#include "globalincs/alphacolors.h"
#include "graphics/grbatch.h"
#include "graphics/tmapper.h"
#include "io/key.h"
#include "physics/physics.h"
#include "render/3dinternal.h"
#include "graphics/2d.h"

Go to the source code of this file.

Classes

struct  horz_pt
 

Macros

#define TRIANGLE_AREA(_p, _q, _r)
 
#define MAX_ROD_VECS   100
 
#define MAX_PERSPECTIVE_DIVISIONS   5
 
#define uw(p)   (*((uint *) (p)))
 
#define w(p)   (*((int *) (p)))
 
#define wp(p)   ((int *) (p))
 
#define vp(p)   ((vec3d *) (p))
 
#define fl(p)   (*((float *) (p)))
 
#define OP_EOF   0
 
#define OP_DEFPOINTS   1
 
#define OP_FLATPOLY   2
 
#define OP_TMAPPOLY   3
 
#define OP_SORTNORM   4
 
#define OP_BOUNDBOX   5
 

Typedefs

typedef struct horz_pt horz_pt
 

Functions

int must_clip_line (vertex *p0, vertex *p1, ubyte codes_or, uint flags)
 
int g3_draw_line (vertex *p0, vertex *p1)
 
int g3_check_normal_facing (const vec3d *v, const vec3d *norm)
 
int do_facing_check (const vec3d *norm, vertex **vertlist, const vec3d *p)
 
int g3_draw_poly_if_facing (int nv, vertex **pointlist, uint tmap_flags, const vec3d *norm, const vec3d *pnt)
 
int g3_draw_poly (int nv, vertex **pointlist, uint tmap_flags)
 
int g3_draw_polygon (const vec3d *pos, const matrix *ori, float width, float height, int tmap_flags)
 
int g3_draw_polygon (const vec3d *pos, const vec3d *norm, float width, float height, int tmap_flags)
 
int g3_draw_poly_constant_sw (int nv, vertex **pointlist, uint tmap_flags, float constant_sw)
 
int g3_draw_sphere (vertex *pnt, float rad)
 
int g3_draw_sphere_ez (const vec3d *pnt, float rad)
 
int g3_draw_bitmap_3d (vertex *pnt, int orient, float rad, uint tmap_flags, float depth)
 
int g3_draw_bitmap_3d_v (vertex *pnt, int orient, float rad, uint tmap_flags, float depth, float c)
 
int g3_draw_bitmap_3d_volume (vertex *pnt, int orient, float rad, uint tmap_flags, float depth, int resolution)
 
int g3_draw_bitmap (vertex *pnt, int orient, float rad, uint tmap_flags, float depth)
 
int g3_get_bitmap_dims (int bitmap, vertex *pnt, float rad, int *x, int *y, int *w, int *h, int *size)
 
int g3_draw_rotated_bitmap_3d (vertex *pnt, float angle, float rad, uint tmap_flags, float depth)
 
int g3_draw_rotated_bitmap (vertex *pnt, float angle, float rad, uint tmap_flags, float depth)
 
float g3_get_poly_area (int nv, vertex **pointlist)
 
float g3_draw_poly_constant_sw_area (int nv, vertex **pointlist, uint tmap_flags, float constant_sw, float area)
 
float g3_draw_rotated_bitmap_area (vertex *pnt, float angle, float rad, uint tmap_flags, float area)
 
void g3_draw_horizon_line ()
 
int g3_draw_rod (const vec3d *p0, float width1, const vec3d *p1, float width2, vertex *verts, uint tmap_flags)
 
int g3_draw_rod (int num_points, const vec3d *pvecs, float width, uint tmap_flags)
 
void stars_project_2d_onto_sphere (vec3d *pnt, float rho, float phi, float theta)
 
int g3_draw_perspective_bitmap (const angles *a, float scale_x, float scale_y, int div_x, int div_y, uint tmap_flags)
 
void g3_draw_2d_shield_icon (const coord2d coords[6], const int r, const int g, const int b, const int a)
 
void g3_draw_2d_rect (int x, int y, int w, int h, int r, int g, int b, int a)
 
int g3_draw_2d_poly_bitmap (float x, float y, float w, float h, uint additional_tmap_flags)
 
void bm_list_shutdown ()
 
int g3_draw_2d_poly_bitmap_list (bitmap_2d_list *b_list, int n_bm, uint additional_tmap_flags)
 
int g3_draw_2d_poly_bitmap_rect_list (bitmap_rect_list *b_list, int n_bm, uint additional_tmap_flags)
 
void g3_draw_htl_line (const vec3d *start, const vec3d *end)
 
void g3_draw_htl_sphere (const vec3d *position, float radius)
 

Variables

vec3d g3_square [4]
 
float p_phi = 10.0f
 
float p_theta = 10.0f
 
vertexbitmap_2d_poly_list =NULL
 
vertex ** bitmap_2d_poly_vertlist =NULL
 
int bitmap_2d_poly_list_size =0
 

Macro Definition Documentation

#define fl (   p)    (*((float *) (p)))

Definition at line 2063 of file 3ddraw.cpp.

#define MAX_PERSPECTIVE_DIVISIONS   5

Definition at line 1417 of file 3ddraw.cpp.

#define MAX_ROD_VECS   100

Definition at line 1334 of file 3ddraw.cpp.

#define OP_BOUNDBOX   5

Definition at line 2100 of file 3ddraw.cpp.

#define OP_DEFPOINTS   1

Definition at line 2096 of file 3ddraw.cpp.

#define OP_EOF   0

Definition at line 2095 of file 3ddraw.cpp.

#define OP_FLATPOLY   2

Definition at line 2097 of file 3ddraw.cpp.

#define OP_SORTNORM   4

Definition at line 2099 of file 3ddraw.cpp.

#define OP_TMAPPOLY   3

Definition at line 2098 of file 3ddraw.cpp.

#define TRIANGLE_AREA (   _p,
  _q,
  _r 
)
Value:
do {\
vec3d a, b, cross;\
\
a.xyz.x = _q->world.xyz.x - _p->world.xyz.x;\
a.xyz.y = _q->world.xyz.y - _p->world.xyz.y;\
a.xyz.z = 0.0f;\
\
b.xyz.x = _r->world.xyz.x - _p->world.xyz.x;\
b.xyz.y = _r->world.xyz.y - _p->world.xyz.y;\
b.xyz.z = 0.0f;\
vm_vec_cross(&cross, &a, &b);\
total_area += vm_vec_mag(&cross) * 0.5f;\
} while(0);
float vm_vec_mag(const vec3d *v)
Definition: vecmat.cpp:325
struct vec3d vec3d
GLboolean GLboolean GLboolean GLboolean a
Definition: Glext.h:5781
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
vec3d * vm_vec_cross(vec3d *dest, const vec3d *src0, const vec3d *src1)
Definition: vecmat.cpp:645

As a define only for readability.

Definition at line 938 of file 3ddraw.cpp.

#define uw (   p)    (*((uint *) (p)))

Definition at line 2059 of file 3ddraw.cpp.

#define vp (   p)    ((vec3d *) (p))

Definition at line 2062 of file 3ddraw.cpp.

#define w (   p)    (*((int *) (p)))

Definition at line 2060 of file 3ddraw.cpp.

#define wp (   p)    ((int *) (p))

Definition at line 2061 of file 3ddraw.cpp.

Typedef Documentation

typedef struct horz_pt horz_pt

Function Documentation

void bm_list_shutdown ( )

Definition at line 1789 of file 3ddraw.cpp.

int do_facing_check ( const vec3d norm,
vertex **  vertlist,
const vec3d p 
)

Definition at line 166 of file 3ddraw.cpp.

int g3_check_normal_facing ( const vec3d v,
const vec3d norm 
)

Returns true if a plane is facing the viewer.

Takes the unrotated surface normal of the plane, and a point on it. The normal need not be normalized

Definition at line 155 of file 3ddraw.cpp.

int g3_draw_2d_poly_bitmap ( float  x,
float  y,
float  w,
float  h,
uint  additional_tmap_flags = 0 
)

Draw a 2d bitmap on a poly

Definition at line 1728 of file 3ddraw.cpp.

int g3_draw_2d_poly_bitmap_list ( bitmap_2d_list b_list,
int  n_bm,
uint  additional_tmap_flags 
)

Definition at line 1794 of file 3ddraw.cpp.

int g3_draw_2d_poly_bitmap_rect_list ( bitmap_rect_list b_list,
int  n_bm,
uint  additional_tmap_flags 
)

Definition at line 1885 of file 3ddraw.cpp.

void g3_draw_2d_rect ( int  x,
int  y,
int  w,
int  h,
int  r,
int  g,
int  b,
int  a 
)

Draw a 2D rectangle

Definition at line 1651 of file 3ddraw.cpp.

void g3_draw_2d_shield_icon ( const coord2d  coords[6],
const int  r,
const int  g,
const int  b,
const int  a 
)

Draw a 2D shield icon w/ 6 points

Definition at line 1551 of file 3ddraw.cpp.

int g3_draw_bitmap ( vertex pos,
int  orient,
float  radius,
uint  tmap_flags,
float  depth = 0.0f 
)

Draws a bitmap with the specified 3d width & height

Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.

Returns
Returns 1 if off screen, 0 if drawn

If bitmap is not square, rad will be the 3d size of the smallest dimension. orient flips the bitmap in some way. Pass 0 for normal or else pass a random nuber between 0 and 7, inclusive.

Definition at line 649 of file 3ddraw.cpp.

int g3_draw_bitmap_3d ( vertex pnt,
int  orient,
float  rad,
uint  tmap_flags,
float  depth 
)

Definition at line 521 of file 3ddraw.cpp.

int g3_draw_bitmap_3d_v ( vertex pnt,
int  orient,
float  rad,
uint  tmap_flags,
float  depth,
float  c 
)

Definition at line 587 of file 3ddraw.cpp.

int g3_draw_bitmap_3d_volume ( vertex pnt,
int  orient,
float  rad,
uint  tmap_flags,
float  depth,
int  resolution 
)

Definition at line 633 of file 3ddraw.cpp.

void g3_draw_horizon_line ( )

Draws a line representing the horizon

Definition at line 1168 of file 3ddraw.cpp.

void g3_draw_htl_line ( const vec3d start,
const vec3d end 
)

Draw a line in HTL mode without having to go through the rotate/project stuff

Definition at line 1975 of file 3ddraw.cpp.

void g3_draw_htl_sphere ( const vec3d position,
float  radius 
)

Draw a sphere mode without having to go through the rotate/project stuff

Definition at line 1984 of file 3ddraw.cpp.

int g3_draw_line ( vertex p0,
vertex p1 
)

Draws a line. takes two points. returns true if drew

Definition at line 112 of file 3ddraw.cpp.

int g3_draw_perspective_bitmap ( const angles a,
float  scale_x,
float  scale_y,
int  div_x,
int  div_y,
uint  tmap_flags 
)

Draw a perspective bitmap based on angles and radius

Definition at line 1434 of file 3ddraw.cpp.

int g3_draw_poly ( int  nv,
vertex **  pointlist,
uint  tmap_flags 
)

Draw a polygon.

Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.

Returns
Returns 1 if off screen, 0 if drawn

Definition at line 207 of file 3ddraw.cpp.

int g3_draw_poly_constant_sw ( int  nv,
vertex **  pointlist,
uint  tmap_flags,
float  constant_sw 
)

Draw a polygon.

Same as g3_draw_poly, but it bashes sw to a constant value for all vertexes. Needs to be done after clipping to get them all.

Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.

Returns
Returns 1 if off screen, 0 if drawn

Definition at line 381 of file 3ddraw.cpp.

float g3_draw_poly_constant_sw_area ( int  nv,
vertex **  pointlist,
uint  tmap_flags,
float  constant_sw,
float  area 
)

Definition at line 971 of file 3ddraw.cpp.

int g3_draw_poly_if_facing ( int  nv,
vertex **  pointlist,
uint  tmap_flags,
const vec3d norm,
const vec3d pnt 
)

Like g3_draw_poly(), but checks to see if facing.

If surface normal is NULL, this routine must compute it, which will be slow. It is better to pre-compute the normal, and pass it to this function. When the normal is passed, this function works like g3_check_normal_facing() plus g3_draw_poly().

Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.

Returns
Returns -1 if not facing, 1 if off screen, 0 if drawn

Definition at line 194 of file 3ddraw.cpp.

int g3_draw_polygon ( const vec3d pos,
const matrix ori,
float  width,
float  height,
int  tmap_flags 
)

Definition at line 310 of file 3ddraw.cpp.

int g3_draw_polygon ( const vec3d pos,
const vec3d norm,
float  width,
float  height,
int  tmap_flags 
)

Definition at line 369 of file 3ddraw.cpp.

int g3_draw_rod ( const vec3d p0,
float  width1,
const vec3d p1,
float  width2,
vertex verts,
uint  tmap_flags 
)

Draws a polygon always facing the viewer. Compute the corners of a rod. fills in vertbuf. Verts has any needs uv's or l's or can be NULL if none needed.

Definition at line 1262 of file 3ddraw.cpp.

int g3_draw_rod ( int  num_points,
const vec3d pvecs,
float  width,
uint  tmap_flags 
)

Definition at line 1335 of file 3ddraw.cpp.

int g3_draw_rotated_bitmap ( vertex pnt,
float  angle,
float  radius,
uint  tmap_flags,
float  depth = 0.0f 
)

Draw a bitmap that is always facing, but rotates.

If bitmap is not square, rad will be the 3d size of the smallest dimension.

Definition at line 844 of file 3ddraw.cpp.

int g3_draw_rotated_bitmap_3d ( vertex pnt,
float  angle,
float  rad,
uint  tmap_flags,
float  depth 
)

Definition at line 788 of file 3ddraw.cpp.

float g3_draw_rotated_bitmap_area ( vertex pnt,
float  angle,
float  rad,
uint  tmap_flags,
float  area 
)

Definition at line 1069 of file 3ddraw.cpp.

int g3_draw_sphere ( vertex pnt,
float  rad 
)

Draw a sortof sphere - i.e., the 2d radius is proportional to the 3d radius, but not to the distance from the eye. Uses the current 2d color.

Definition at line 475 of file 3ddraw.cpp.

int g3_draw_sphere_ez ( const vec3d pnt,
float  rad 
)

Same as g3_draw_sphere, but you pass a vector and this rotates and projects it and then call g3_draw_sphere.

Definition at line 498 of file 3ddraw.cpp.

int g3_get_bitmap_dims ( int  bitmap,
vertex pos,
float  radius,
int x,
int y,
int w,
int h,
int size 
)

Get bitmap dims onscreen as if g3_draw_bitmap() had been called

Definition at line 740 of file 3ddraw.cpp.

float g3_get_poly_area ( int  nv,
vertex **  pointlist 
)

Definition at line 953 of file 3ddraw.cpp.

int must_clip_line ( vertex p0,
vertex p1,
ubyte  codes_or,
uint  flags 
)

Deal with a clipped line

Definition at line 71 of file 3ddraw.cpp.

void stars_project_2d_onto_sphere ( vec3d pnt,
float  rho,
float  phi,
float  theta 
)

Definition at line 1419 of file 3ddraw.cpp.

Variable Documentation

vertex* bitmap_2d_poly_list =NULL

Definition at line 1785 of file 3ddraw.cpp.

int bitmap_2d_poly_list_size =0

Definition at line 1787 of file 3ddraw.cpp.

vertex** bitmap_2d_poly_vertlist =NULL

Definition at line 1786 of file 3ddraw.cpp.

vec3d g3_square[4]
Initial value:
= {
{ { { -1.0f, -1.0f, 20.0f } } },
{ { { -1.0f, 1.0f, 20.0f } } },
{ { { 1.0f, 1.0f, 20.0f } } },
{ { { 1.0f, -1.0f, 20.0f } } }
}

Definition at line 1410 of file 3ddraw.cpp.

float p_phi = 10.0f

Definition at line 1432 of file 3ddraw.cpp.

float p_theta = 10.0f

Definition at line 1433 of file 3ddraw.cpp.