TWOD.H

[目次 | 型・クラス・構造体 | マクロ]

目次

型・クラス・構造体一覧

マクロ一覧


   1|/**************************************************************************
   2|*  1. <<< 二次元グラフィックス(代数)(TwoD) >>> 
   3|***************************************************************************/
   4|
   5|#ifndef __TWOD_H
   6|#define __TWOD_H
   7|
   8|/*----------------------------------------------------------------------
   9|[Module Property]
  10|name = TwoD
  11|title = 二次元グラフィックス(代数)
  12|category = グラフィック
  13|src = twod.c
  14|depend =
  15|priority =
  16|accord =
  17|----------------------------------------------------------------------*/
  18|
  19|#ifndef USES_PRIORITY_HEADER
  20|/*[START_OF_PRIORITY_HEADER]*/
  21|
  22|#ifndef  TWOD_TYPEDEF
  23|#define  TWOD_TYPEDEF
  24|
  25|#define  USES_TWOD
  26|
  27|typedef struct _TwoD_XY     TwoD_XY;
  28|typedef struct _TwoD_Poly   TwoD_Poly;
  29|
  30|#define  STDLIBS_INCLUDE_STDIO_H
  31|#define  STDLIBS_INCLUDE_STDLIB_H
  32|
  33|#endif
  34|
  35|/*[END_OF_PRIORITY_HEADER]*/
  36|#endif /* USES_PRIORITY_HEADER */
  37|
  38|
  39|#ifdef _STDLIB
  40|#include <stdlib.h>
  41|#endif
  42|
  43|
  44| 
  45|/*------------------------------------------------------------------------*/
  46|/* 2. <<< Interface Area ----------------------------------------------- >>> */ 
  47|/*------------------------------------------------------------------------*/
  48|
  49|
  50| 
  51|/**************************************************************************
  52|* 3. <<< [TwoD_XY] 二次元座標 >>> 
  53|***************************************************************************/
  54|struct _TwoD_XY {
  55|  double  x, y;
  56|};
  57|
  58|void  TwoD_XY_init( TwoD_XY*, double x, double y );
  59|int   TwoD_XY_getOutProd( TwoD_XY*, TwoD_XY* );
  60|void  TwoD_XY_rot( TwoD_XY*, const TwoD_XY* center, double radian );
  61|#ifdef USES_THREED
  62|void  TwoD_XY_initBy3D( TwoD_XY*, ThreeD_TwoD* f, ThreeD_XYZ* p );
  63|#endif
  64|int   TwoD_XY_getCrossLineH( double y, TwoD_XY* p1, TwoD_XY* p2,
  65|  TwoD_XY* out );
  66|bool  TwoD_XY_isInPoly( TwoD_XY* p, TwoD_Poly* poly );
  67|#ifndef  ERRORS_CUT_DEBUG_TOOL
  68|void  TwoD_XY_print( TwoD_XY* );
  69|#endif
  70|
  71|
  72| 
  73|/**************************************************************************
  74|* 4. <<< [TwoD_Poly] ポリゴン >>> 
  75|***************************************************************************/
  76|struct _TwoD_Poly {
  77|  TwoD_XY*  p_array;  /* 頂点座標の配列の先頭アドレス */
  78|  int  n;             /* n 角形 */
  79|  int  color;         /* 色 */
  80|};
  81|
  82|void  TwoD_Poly_init( TwoD_Poly*, TwoD_XY* p_array, int n, int color );
  83|int   TwoD_Poly_getConvexType( TwoD_Poly* );
  84|#ifdef USES_THREED
  85|void  TwoD_Poly_initByThreeD( TwoD_Poly*, TwoD_XY* p_array,
  86|  size_t p_array_sizeof, ThreeD_Poly* poly3, ThreeD_ViewL* view );
  87|void  TwoD_Poly_initByThreeD2( TwoD_Poly*, TwoD_XY* p_array,
  88|  size_t p_array_sizeof, ThreeD_TwoD* f, ThreeD_Poly* poly3 );
  89|#endif /* USES_THREED */
  90|
  91|void  TwoD_Poly_print( TwoD_Poly* );
  92|
  93|
  94|/* 5. <<< [TwoD_LeftConvex,TwoD_RightConvex,TwoD_NotConvex,TwoD_NotPoly] >>> */
  95|#define  TwoD_LeftConvex     1  /* 左回り凸型 */
  96|#define  TwoD_RightConvex   -1  /* 右回り凸型 */
  97|#define  TwoD_NotConvex      0  /* 凹型 */
  98|#define  TwoD_NotPoly       99  /* 多角形でない */
  99|
 100| 
 101|/*------------------------------------------------------------------------*/
 102|/* 6. <<< Mapping Area ------------------------------------------------- >>> */ 
 103|/*------------------------------------------------------------------------*/
 104|
 105|
 106| 
 107|/*************************************************************************
 108|*  7. <<< [TwoD_XY_init] 座標を設定する >>> 
 109|**************************************************************************/
 110|#define  TwoD_XY_init( this, x0, y0 ) \
 111|  ((this)->x = (x0),  (this)->y = (y0))
 112|
 113|
 114| 
 115|/*************************************************************************
 116|*  8. <<< [TwoD_XY_getOutProd] 外積を求める >>> 
 117|*【引数】
 118|*  ・TwoD_XY*  v1,v2;    外積のパラメータ(ベクトル)
 119|*  ・double    返り値;   外積のベクトル成分
 120|*【補足】
 121|*・返り値は、v1 が v2 から見て左向きの場合、正の値、
 122|*  平行の場合、0、右向きの場合、負の値が返ります。
 123|*  (ただし、X 軸の左向きが Y 軸の場合)
 124|*  一般のグラフィック画面では逆になります。
 125|*・一般の外積は、三次元ベクトルです。
 126|**************************************************************************/
 127|#define  TwoD_XY_getOutProd( v1, v2 ) \
 128|  ( (v1)->x * (v2)->y - (v1)->y * (v2)->x )
 129|
 130|
 131| 
 132|#endif 
 133| 
 134|