FS2_Open
Open source remastering of the Freespace 2 engine
3d.h File Reference
#include "camera/camera.h"
#include "graphics/2d.h"
#include "graphics/grbatch.h"
#include "graphics/tmapper.h"
#include "math/vecmat.h"

Go to the source code of this file.

Classes

struct  flash_beam
 
class  flash_ball
 

Macros

#define PF_PROJECTED   1
 
#define PF_OVERFLOW   2
 
#define PF_TEMP_POINT   4
 
#define CC_OFF_LEFT   1
 
#define CC_OFF_RIGHT   2
 
#define CC_OFF_BOT   4
 
#define CC_OFF_TOP   8
 
#define CC_OFF_USER   16
 
#define CC_BEHIND   0x80
 
#define CC_OFF   (CC_OFF_LEFT | CC_OFF_RIGHT | CC_OFF_BOT | CC_OFF_TOP | CC_OFF_USER | CC_BEHIND)
 
#define g3_start_frame(zbuffer_flag)   g3_start_frame_func(zbuffer_flag, __FILE__, __LINE__ )
 
#define g3_end_frame()   g3_end_frame_func( __FILE__, __LINE__ )
 

Functions

void g3_start_frame_func (int zbuffer_flag, const char *filename, int lineno)
 
void g3_end_frame_func (const char *filename, int lineno)
 
int g3_in_frame ()
 
void g3_set_view_angles (const vec3d *view_pos, const angles *view_orient, float zoom)
 
void g3_set_view (camera *cam)
 
void g3_set_view_matrix (const vec3d *view_pos, const matrix *view_matrix, float zoom)
 
void g3_draw_horizon (int sky_color, int ground_color)
 
void g3_draw_horizon_line ()
 
int g3_compute_sky_polygon (float *points_2d, vec3d *vecs)
 
void g3_start_instance_matrix (const vec3d *pos, const matrix *orient, bool set_api=true)
 
void g3_start_instance_angles (const vec3d *pos, const angles *orient)
 
void g3_done_instance (bool set_api=false)
 
void g3_get_FOV (float *fov_x, float *fov_y)
 
float g3_get_zoom (char axis, float fov, int window_width, int window_height)
 
void g3_get_view_vectors (vec3d *forward, vec3d *up, vec3d *right)
 
int g3_check_normal_facing (const vec3d *v, const vec3d *norm)
 
ccodes g3_check_codes (int nv, vertex **pointlist)
 
ubyte g3_rotate_vertex (vertex *dest, const vec3d *src)
 
ubyte g3_rotate_vertex_popped (vertex *dest, const vec3d *src)
 
ubyte g3_rotate_faraway_vertex (vertex *dest, const vec3d *src)
 
int g3_project_vertex (vertex *point)
 
ubyte g3_project_vector (const vec3d *p, float *sx, float *sy)
 
ubyte g3_rotate_vector (vec3d *dest, const vec3d *src)
 
ubyte g3_code_vector (const vec3d *p)
 
float g3_calc_point_depth (const vec3d *pnt)
 
void g3_point_to_vec (vec3d *v, int sx, int sy)
 
void g3_point_to_vec_delayed (vec3d *v, int sx, int sy)
 
ubyte g3_code_vertex (vertex *point)
 
vec3dg3_rotate_delta_x (vec3d *dest, float dx)
 
vec3dg3_rotate_delta_y (vec3d *dest, float dy)
 
vec3dg3_rotate_delta_z (vec3d *dest, float dz)
 
vec3dg3_rotate_delta_vec (vec3d *dest, vec3d *src)
 
ubyte g3_add_delta_vec (vertex *dest, vertex *src, vec3d *deltav)
 
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=TMAP_FLAG_TEXTURED)
 
int g3_draw_polygon (const vec3d *pos, const vec3d *norm, float width, float height, int tmap_flags=TMAP_FLAG_TEXTURED)
 
int g3_draw_poly_constant_sw (int nv, vertex **pointlist, uint tmap_flags, float constant_sw)
 
int g3_draw_poly_if_facing (int nv, vertex **pointlist, uint tmap_flags, const vec3d *norm, const vec3d *pnt)
 
int g3_draw_line (vertex *p0, vertex *p1)
 
int g3_draw_rod (const vec3d *p0, float width1, const vec3d *p1, float width2, vertex *verts, uint tmap_flags)
 
int g3_draw_bitmap (vertex *pos, int orient, float radius, uint tmap_flags, float depth=0.0f)
 
int g3_get_bitmap_dims (int bitmap, vertex *pos, float radius, int *x, int *y, int *w, int *h, int *size)
 
int g3_draw_sphere (vertex *pnt, float rad)
 
int g3_draw_sphere_ez (const vec3d *pnt, float rad)
 
float g3_draw_laser (const vec3d *headp, float head_width, const vec3d *tailp, float tail_width, uint tmap_flags=TMAP_FLAG_TEXTURED, float max_len=0.0f)
 
float g3_draw_laser_rgb (const vec3d *headp, float head_width, const vec3d *tailp, float tail_width, int r, int g, int b, uint tmap_flags=TMAP_FLAG_TEXTURED|TMAP_FLAG_RGB, float max_len=0.0f)
 
int g3_draw_rotated_bitmap (vertex *pnt, float angle, float radius, uint tmap_flags, float depth=0.0f)
 
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=0)
 
void g3_start_user_clip_plane (const vec3d *plane_point, const vec3d *plane_normal)
 
void g3_stop_user_clip_plane ()
 
ubyte g3_transfer_vertex (vertex *dest, const vec3d *src)
 
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

matrix View_matrix
 
vec3d View_position
 
matrix Light_matrix
 
vec3d Light_base
 
matrix Eye_matrix
 
vec3d Eye_position
 
float Eye_fov
 
vec3d Object_position
 
matrix Object_matrix
 
float Proj_fov
 

Macro Definition Documentation

#define CC_BEHIND   0x80

Definition at line 31 of file 3d.h.

Definition at line 34 of file 3d.h.

#define CC_OFF_BOT   4

Definition at line 28 of file 3d.h.

#define CC_OFF_LEFT   1

Definition at line 26 of file 3d.h.

#define CC_OFF_RIGHT   2

Definition at line 27 of file 3d.h.

#define CC_OFF_TOP   8

Definition at line 29 of file 3d.h.

#define CC_OFF_USER   16

Definition at line 30 of file 3d.h.

#define g3_end_frame ( )    g3_end_frame_func( __FILE__, __LINE__ )

End the frame

Definition at line 49 of file 3d.h.

#define g3_start_frame (   zbuffer_flag)    g3_start_frame_func(zbuffer_flag, __FILE__, __LINE__ )

Start the frame. Pass non-zero to enable zbuffering

Definition at line 39 of file 3d.h.

#define PF_OVERFLOW   2

Definition at line 22 of file 3d.h.

#define PF_PROJECTED   1

Definition at line 21 of file 3d.h.

#define PF_TEMP_POINT   4

Definition at line 23 of file 3d.h.

Function Documentation

ubyte g3_add_delta_vec ( vertex dest,
vertex src,
vec3d deltav 
)
float g3_calc_point_depth ( const vec3d pnt)

Calculate the depth of a point - returns the z coord of the rotated point

Definition at line 278 of file 3dmath.cpp.

ccodes g3_check_codes ( int  nv,
vertex **  pointlist 
)

Returns codes_and & codes_or of a list of points numbers

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.

ubyte g3_code_vector ( const vec3d p)

Codes a vector.

Returns
Returns the codes of a point.

Codes a vector. Returns the codes of a point.

Definition at line 21 of file 3dmath.cpp.

ubyte g3_code_vertex ( vertex p)

Code a point. fills in the p3_codes field of the point, and returns the codes

Definition at line 54 of file 3dmath.cpp.

int g3_compute_sky_polygon ( float points_2d,
vec3d vecs 
)

Get vectors that are edge of horizon

void g3_done_instance ( bool  use_api)

Pops the old context

Definition at line 341 of file 3dsetup.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.

void g3_draw_horizon ( int  sky_color,
int  ground_color 
)

Draw a horizon

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.

float g3_draw_laser ( const vec3d headp,
float  head_width,
const vec3d tailp,
float  tail_width,
uint  tmap_flags = TMAP_FLAG_TEXTURED,
float  max_len = 0.0f 
)

Draw a laser shaped 3d looking thing.

If max_len is > 1.0, then this caps the length to be no longer than max_len pixels

Definition at line 116 of file 3dlaser.cpp.

float g3_draw_laser_rgb ( const vec3d headp,
float  head_width,
const vec3d tailp,
float  tail_width,
int  r,
int  g,
int  b,
uint  tmap_flags = TMAP_FLAG_TEXTURED|TMAP_FLAG_RGB,
float  max_len = 0.0f 
)

Draw a laser shaped 3d looking thing using vertex coloring (useful for things like colored laser glows)

If max_len is > 1.0, then this caps the length to be no longer than max_len pixels

Definition at line 267 of file 3dlaser.cpp.

int g3_draw_line ( vertex p0,
vertex p1 
)

Draws a line.

Parameters
p0First point
p1Second point

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.

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 = TMAP_FLAG_TEXTURED 
)

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 = TMAP_FLAG_TEXTURED 
)

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_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_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.

void g3_end_frame_func ( const char *  filename,
int  lineno 
)

This doesn't do anything, but is here for completeness

Definition at line 126 of file 3dsetup.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.

void g3_get_FOV ( float fov_x,
float fov_y 
)

Get current field of view. Fills in angle for x & y

void g3_get_view_vectors ( vec3d forward,
vec3d up,
vec3d right 
)

Returns the normalized, unscaled view vectors

float g3_get_zoom ( char  axis,
float  fov,
int  window_width,
int  window_height 
)

Get zoom.

For a given window size, return the zoom which will achieve the given FOV along the given axis.

int g3_in_frame ( )

Currently in frame?

Check if in frame

Definition at line 66 of file 3dsetup.cpp.

void g3_point_to_vec ( vec3d v,
int  sx,
int  sy 
)

From a 2d point, compute the vector through that point

Definition at line 231 of file 3dmath.cpp.

void g3_point_to_vec_delayed ( vec3d v,
int  sx,
int  sy 
)

From a 2d point, compute the vector through that point.

This can be called outside of a g3_start_frame/g3_end_frame pair as long g3_start_frame was previously called.

Definition at line 254 of file 3dmath.cpp.

ubyte g3_project_vector ( const vec3d p,
float sx,
float sy 
)

Projects a vector

Definition at line 184 of file 3dmath.cpp.

int g3_project_vertex ( vertex p)

Projects a point

Projects a point. Checks for overflow.

Definition at line 202 of file 3dmath.cpp.

vec3d* g3_rotate_delta_vec ( vec3d dest,
vec3d src 
)
vec3d* g3_rotate_delta_x ( vec3d dest,
float  dx 
)
vec3d* g3_rotate_delta_y ( vec3d dest,
float  dy 
)
vec3d* g3_rotate_delta_z ( vec3d dest,
float  dz 
)
ubyte g3_rotate_faraway_vertex ( vertex dest,
const vec3d src 
)

Use this for stars, etc

Definition at line 156 of file 3dmath.cpp.

ubyte g3_rotate_vector ( vec3d dest,
const vec3d src 
)

Rotates a point.

Returns
Returns codes.

Rotates a point. returns codes. does not check if already rotated

Definition at line 171 of file 3dmath.cpp.

ubyte g3_rotate_vertex ( vertex dest,
const vec3d src 
)

Rotates a point. returns codes. does not check if already rotated

Definition at line 97 of file 3dmath.cpp.

ubyte g3_rotate_vertex_popped ( vertex dest,
const vec3d src 
)

Same as above, only ignores the current instancing

Definition at line 228 of file 3dsetup.cpp.

void g3_set_view ( camera cam)

Set view from camera

Definition at line 137 of file 3dsetup.cpp.

void g3_set_view_angles ( const vec3d view_pos,
const angles view_orient,
float  zoom 
)

Set view from x,y,z & p,b,h, zoom. Must call one of g3_set_view_*()

Definition at line 182 of file 3dsetup.cpp.

void g3_set_view_matrix ( const vec3d view_pos,
const matrix view_matrix,
float  zoom 
)

Set view from x,y,z, viewer matrix, and zoom. Must call one of g3_set_view_*()

Definition at line 152 of file 3dsetup.cpp.

void g3_start_frame_func ( int  zbuffer_flag,
const char *  filename,
int  lineno 
)

Use the g3_start_frame macro instead of calling this directly.

Start the frame Pass true for zbuffer_flag to turn on zbuffering

Definition at line 75 of file 3dsetup.cpp.

void g3_start_instance_angles ( const vec3d pos,
const angles orient 
)

Instance at specified point with specified orientation

Instance at specified point with specified orientation

If angles==NULL, don't modify matrix. This will be like doing an offset

Definition at line 317 of file 3dsetup.cpp.

void g3_start_instance_matrix ( const vec3d pos,
const matrix orient,
bool  set_api 
)

Instance at specified point with specified orientation

nstance at specified point with specified orientation

if matrix==NULL, don't modify matrix. This will be like doing an offset if pos==NULL, no position change

Definition at line 249 of file 3dsetup.cpp.

void g3_start_user_clip_plane ( const vec3d plane_point,
const vec3d plane_normal 
)

Enables clipping with an arbritary plane.

This will be on until g3_stop_clip_plane is called or until next frame. The points passed should be relative to the instance. Probably that means world coordinates.

This works like any other clip plane... if this is enabled and you rotate a point, the CC_OFF_USER bit will be set in the clipping codes. It is completely handled by most g3_draw primitives, except maybe lines.

As far as performance, when enabled, it will slow down each point rotation (or g3_code_vertex call) by a vec3d subtraction and dot product. It won't slow anything down for polys that are completely clipped on or off by the plane, and will slow each clipped polygon by not much more than any other clipping we do.

Definition at line 381 of file 3dsetup.cpp.

void g3_stop_user_clip_plane ( )

Stops arbritary plane clipping

Definition at line 408 of file 3dsetup.cpp.

ubyte g3_transfer_vertex ( vertex dest,
const vec3d src 
)

Definition at line 84 of file 3dmath.cpp.

Variable Documentation

float Eye_fov

Definition at line 28 of file 3dsetup.cpp.

matrix Eye_matrix

Definition at line 26 of file 3dsetup.cpp.

vec3d Eye_position

Definition at line 27 of file 3dsetup.cpp.

vec3d Light_base

Definition at line 24 of file 3dsetup.cpp.

matrix Light_matrix

Definition at line 23 of file 3dsetup.cpp.

matrix Object_matrix

Definition at line 43 of file 3dsetup.cpp.

vec3d Object_position

Definition at line 42 of file 3dsetup.cpp.

float Proj_fov

Definition at line 31 of file 3dsetup.cpp.

matrix View_matrix

Definition at line 19 of file 3dsetup.cpp.

vec3d View_position

Definition at line 20 of file 3dsetup.cpp.