/* * GRacer * * Copyright (C) 1999 Takashi Matsuda * * 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 2 of the * License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef __GRACER_VERTEX_H__ #define __GRACER_VERTEX_H__ #include #include "gr_global.h" #include #define GR_VERTEX_USE_MACRO typedef union _GrVertexf GrVertexf; typedef union _GrVertexd GrVertexd; typedef GrVertexf GrVertex; union _GrVertexf { struct {GLfloat x, y, z;} c; GLfloat f[3]; }; union _GrVertexd { struct {GLdouble x, y, z;} c; GLdouble f[3]; }; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #if 0 } #endif extern GrVertex *gr_vertex_origin; extern GrVertex *gr_vertex_unit_x; extern GrVertex *gr_vertex_unit_y; extern GrVertex *gr_vertex_unit_z; extern GrVertexd *gr_vertexd_origin; extern GrVertexd *gr_vertexd_unit_x; extern GrVertexd *gr_vertexd_unit_y; extern GrVertexd *gr_vertexd_unit_z; void gr_vertex_rotate (GrVertex *dst, GrVertex *src, float s, float c, float x, float y, float z); /* region specified by v must be convex polygon */ int gr_vertex_check_inner_xy (GrVertex *point, int num, GrVertex *v); void gr_vertex_normalize (GrVertex *d, const GrVertex *s); void gr_vertex_normal (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_normalize_xy (GrVertex *d, const GrVertex *s); void gr_vertex_normalize_yz (GrVertex *d, const GrVertex *s); void gr_vertex_normalize_zx (GrVertex *d, const GrVertex *s); int gr_vertex_near (const GrVertex *v1, const GrVertex *v2, const double threshold); int gr_vertex_near_xy (const GrVertex *v1, const GrVertex *v2, const double threshold); int gr_vertex_near_yz (const GrVertex *v1, const GrVertex *v2, const double threshold); int gr_vertex_near_zx (const GrVertex *v1, const GrVertex *v2, const double threshold); #ifndef GR_VERTEX_USE_MACRO void gr_vertex_copy (GrVertex *v1, GrVertex *v2); int gr_vertex_equal (const GrVertex *v, const GrVertex *w); void gr_vertex_scale (GrVertex *d, const GrVertex *s, const float t); void gr_vertex_scale_a (GrVertex *d, const float t); void gr_vertex_add (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_add_a (GrVertex *d, const GrVertex *s); void gr_vertex_sub (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_sub_a (GrVertex *d, const GrVertex *s); void gr_vertex_cross (GrVertex *d, const GrVertex *v, const GrVertex *w); double gr_vertex_length (const GrVertex *v); double gr_vertex_product (const GrVertex *v, const GrVertex *w); gint gr_vertex_equal_xy (const GrVertex *v, const GrVertex *w); void gr_vertex_scale_xy (GrVertex *d, const GrVertex *s, const float t); void gr_vertex_scale_xya (GrVertex *d, const float t); void gr_vertex_add_xy (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_add_xya (GrVertex *d, const GrVertex *s); void gr_vertex_sub_xy (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_sub_xya (GrVertex *d, const GrVertex *s); void gr_vertex_rot_xy (GrVertex *d, const GrVertex *s, const double sn, const double cs); double gr_vertex_length_xy (const GrVertex *v); double gr_vertex_product_xy (const GrVertex *v, const GrVertex *w); gint gr_vertex_equal_yz (const GrVertex *v, const GrVertex *w); void gr_vertex_scale_yz (GrVertex *d, const GrVertex *s, const float t); void gr_vertex_scale_yza (GrVertex *d, const float t); void gr_vertex_add_yz (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_add_yza (GrVertex *d, const GrVertex *s); void gr_vertex_sub_yz (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_sub_yza (GrVertex *d, const GrVertex *s); void gr_vertex_rot_yz (GrVertex *d, const GrVertex *s, const double sn, const double cs); double gr_vertex_length_yz (const GrVertex *v); double gr_vertex_product_yz (const GrVertex *v, const GrVertex *w); gint gr_vertex_equal_zx (const GrVertex *v, const GrVertex *w); void gr_vertex_scale_zx (GrVertex *d, const GrVertex *s, const float t); void gr_vertex_scale_zxa (GrVertex *d, const float t); void gr_vertex_add_zx (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_add_zxa (GrVertex *d, const GrVertex *s); void gr_vertex_sub_zx (GrVertex *d, const GrVertex *v, const GrVertex *w); void gr_vertex_sub_zxa (GrVertex *d, const GrVertex *s); void gr_vertex_rot_zx (GrVertex *d, const GrVertex *s, const double sn, const double cs); double gr_vertex_length_zx (const GrVertex *v); double gr_vertex_product_zx (const GrVertex *v, const GrVertex *w); #else /* GR_VERTEX_USE_MACRO */ #define gr_vertex_copy(v,w) \ ((v)->c.x = (w)->c.x, (v)->c.y = (w)->c.y, (v)->c.z = (w)->c.z) #define gr_vertex_equal(v,w) \ ((v)->c.x == (w)->c.x && (v)->c.y == (w)->c.y && (v)->c.z == (w)->c.z) #define gr_vertex_scale(d,s,t) \ ((d)->c.x=(s)->c.x*(t), (d)->c.y=(s)->c.y*(t), (d)->c.z=(s)->c.z*(t)) #define gr_vertex_scale_a(d,t) \ ((d)->c.x*=(t), (d)->c.y*=(t), (d)->c.z*=(t)) #define gr_vertex_add(d,v,w) \ ((d)->c.x=(v)->c.x+(w)->c.x,(d)->c.y=(v)->c.y+(w)->c.y,(d)->c.z=(v)->c.z+(w)->c.z) #define gr_vertex_add_a(d,s) \ ((d)->c.x+=(s)->c.x, (d)->c.y+=(s)->c.y, (d)->c.z+=(s)->c.z) #define gr_vertex_sub(d,v,w) \ ((d)->c.x=(v)->c.x-(w)->c.x,(d)->c.y=(v)->c.y-(w)->c.y,(d)->c.z=(v)->c.z-(w)->c.z) #define gr_vertex_sub_a(d,s) \ ((d)->c.x-=(s)->c.x, (d)->c.y-=(s)->c.y, (d)->c.z-=(s)->c.z) #define gr_vertex_cross(d,v,w) \ ((d)->c.x = (v)->c.y*(w)->c.z - (w)->c.y*(v)->c.z, \ (d)->c.y = (w)->c.x*(v)->c.z - (v)->c.x*(w)->c.z, \ (d)->c.z = (v)->c.x*(w)->c.y - (w)->c.x*(v)->c.y) #define gr_vertex_length(v) \ (sqrt((v)->c.x*(v)->c.x + (v)->c.y*(v)->c.y + (v)->c.z*(v)->c.z)) #define gr_vertex_product(v,w) \ ((v)->c.x * (w)->c.x + (v)->c.y * (w)->c.y + (v)->c.z * (w)->c.z) #define gr_vertex_equal_xy(v,w) \ ((v)->c.x == (w)->c.x && (v)->c.y == (w)->c.y) #define gr_vertex_scale_xy(d,s,t) \ ((d)->c.x=(s)->c.x*(t), (d)->c.y=(s)->c.y*(t)) #define gr_vertex_scale_xya(d,t) \ ((d)->c.x*=(t), (d)->c.y*=(t)) #define gr_vertex_add_xy(d,v,w) \ ((d)->c.x=(v)->c.x+(w)->c.x,(d)->c.y=(v)->c.y+(w)->c.y) #define gr_vertex_add_xya(d,s) \ ((d)->c.x+=(s)->c.x, (d)->c.y+=(s)->c.y) #define gr_vertex_sub_xy(d,v,w) \ ((d)->c.x=(v)->c.x-(w)->c.x,(d)->c.y=(v)->c.y-(w)->c.y) #define gr_vertex_sub_xya(d,s) \ ((d)->c.x-=(s)->c.x, (d)->c.y-=(s)->c.y) #define gr_vertex_length_xy(v) \ (sqrt((v)->c.x*(v)->c.x + (v)->c.y*(v)->c.y)) #define gr_vertex_rot_xy(d,s,sn,cs) \ ((d)->c.x=(s)->c.x*cs-(s)->c.y*sn, (d)->c.y=(s)->c.x*sn+(s)->c.y*cs) #define gr_vertex_product_xy(v,w) \ ((v)->c.x * (w)->c.x + (v)->c.y * (w)->c.y) #define gr_vertex_equal_yz(v,w) \ ((v)->c.y == (w)->c.y && (v)->c.z == (w)->c.z) #define gr_vertex_scale_yz(d,s,t) \ ((d)->c.y=(s)->c.y*(t), (d)->c.z=(s)->c.z*(t)) #define gr_vertex_scale_yza(d,t) \ ((d)->c.y*=(t), (d)->c.z*=(t)) #define gr_vertex_add_yz(d,v,w) \ ((d)->c.y=(v)->c.y+(w)->c.y,(d)->c.z=(v)->c.z+(w)->c.z) #define gr_vertex_add_yza(d,s) \ ((d)->c.y+=(s)->c.y, (d)->c.z+=(s)->c.z) #define gr_vertex_sub_yz(d,v,w) \ ((d)->c.y=(v)->c.y-(w)->c.y,(d)->c.z=(v)->c.z-(w)->c.z) #define gr_vertex_sub_yza(d,s) \ ((d)->c.y-=(s)->c.y, (d)->c.z-=(s)->c.z) #define gr_vertex_length_yz(v) \ (sqrt((v)->c.y*(v)->c.y + (v)->c.z*(v)->c.z)) #define gr_vertex_rot_yz(d,s,sn,cs) \ ((d)->c.y=(s)->c.y*cs-(s)->c.z*sn, (d)->c.z=(s)->c.y*sn+(s)->c.z*cs) #define gr_vertex_product_yz(v,w) \ ((v)->c.y * (w)->c.y + (v)->c.z * (w)->c.z) #define gr_vertex_equal_zx(v,w) \ ((v)->c.z == (w)->c.z && (v)->c.x == (w)->c.x) #define gr_vertez_scale_zx(d,s,t) \ ((d)->c.z=(s)->c.z*(t), (d)->c.x=(s)->c.x*(t)) #define gr_vertex_scale_zxa(d,t) \ ((d)->c.z*=(t), (d)->c.x*=(t)) #define gr_vertex_add_zx(d,v,w) \ ((d)->c.z=(v)->c.z+(w)->c.z,(d)->c.x=(v)->c.x+(w)->c.x) #define gr_vertex_add_zxa(d,s) \ ((d)->c.z+=(s)->c.z, (d)->c.x+=(s)->c.x) #define gr_vertex_sub_zx(d,v,w) \ ((d)->c.z=(v)->c.z-(w)->c.z,(d)->c.x=(v)->c.x-(w)->c.x) #define gr_vertex_sub_zxa(d,s) \ ((d)->c.z-=(s)->c.z, (d)->c.x-=(s)->c.x) #define gr_vertex_length_zx(v) \ (sqrt((v)->c.z*(v)->c.z + (v)->c.x*(v)->c.x)) #define gr_vertex_rot_zx(d,s,sn,cs) \ ((d)->c.z=(s)->c.z*cs-(s)->c.x*sn, (d)->c.x=(s)->c.z*sn+(s)->c.x*cs) #define gr_vertex_product_zx(v,w) \ ((v)->c.x * (w)->c.x + (v)->c.z * (w)->c.z) #endif /* GR_VERTEX_USE_MACRO */ #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __GRACER_VERTEX_H__ */