/*
PLIB - A Suite of Portable Game Libraries
Copyright (C) 1998,2002 Steve Baker
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information visit http://plib.sourceforge.net
$Id: sg.h 2121 2007-09-15 03:36:21Z fayjf $
*/
#ifndef SG_H
#define SG_H 1
#include <stdio.h>
#include "ul.h"
#define sgFloat float
#define SGfloat float
#define SG_ZERO 0.0f
#define SG_HALF 0.5f
#define SG_ONE 1.0f
#define SG_TWO 2.0f
#define SG_THREE 3.0f
#define SG_FOUR 4.0f
#define SG_45 45.0f
#define SG_60 60.0f
#define SG_90 90.0f
#define SG_180 180.0f
#define SG_MAX FLT_MAX
#define SG_X 0
#define SG_Y 1
#define SG_Z 2
#define SG_W 3
#ifndef M_PI
#define SG_PI 3.1415926535f
#else
#define SG_PI ((SGfloat) M_PI)
#endif
#define SG_DEGREES_TO_RADIANS (SG_PI/SG_180)
#define SG_RADIANS_TO_DEGREES (SG_180/SG_PI)
/*
These are just convenient redefinitions of standard
math library functions to stop float/double warnings.
*/
inline SGfloat sgSqrt ( const SGfloat x ) { return (SGfloat) sqrt ( x ) ; }
inline SGfloat sgSquare ( const SGfloat x ) { return x * x ; }
inline SGfloat sgAbs ( const SGfloat a ) { return (a<SG_ZERO) ? -a : a ; }
inline SGfloat sgHypot ( const SGfloat x, const SGfloat y ) { return sgSqrt( sgSquare(x) + sgSquare(y) ); }
/*
Type-casted sin/cos/tan/asin/acos/atan2 ANGLES IN DEGREES
*/
inline SGfloat sgASin ( SGfloat s )
{ return (SGfloat) asin ( s ) * SG_RADIANS_TO_DEGREES ; }
inline SGfloat sgACos ( SGfloat s )
{ return (SGfloat) acos ( s ) * SG_RADIANS_TO_DEGREES ; }
inline SGfloat sgATan ( SGfloat s )
{ return (SGfloat) atan ( s ) * SG_RADIANS_TO_DEGREES ; }
inline SGfloat sgATan2 ( SGfloat y, SGfloat x )
{ return (SGfloat) atan2 ( y,x ) * SG_RADIANS_TO_DEGREES ; }
inline SGfloat sgSin ( SGfloat s )
{ return (SGfloat) sin ( s * SG_DEGREES_TO_RADIANS ) ; }
inline SGfloat sgCos ( SGfloat s )
{ return (SGfloat) cos ( s * SG_DEGREES_TO_RADIANS ) ; }
inline SGfloat sgTan ( SGfloat s )
{ return (SGfloat) tan ( s * SG_DEGREES_TO_RADIANS ) ; }
inline int sgCompareFloat ( const SGfloat a, const SGfloat b, const SGfloat tol )
{
if ( ( a + tol ) < b ) return -1 ;
if ( ( b + tol ) < a ) return 1 ;
return 0 ;
}
/*
Types used in SG.
*/
typedef SGfloat sgVec2 [ 2 ] ;
typedef SGfloat sgVec3 [ 3 ] ;
typedef SGfloat sgVec4 [ 4 ] ;
typedef sgVec4 sgQuat ;
typedef SGfloat sgMat3 [3][3] ;
typedef SGfloat sgMat4 [4][4] ;
struct sgCoord
{
sgVec3 xyz ;
sgVec3 hpr ;
} ;
class sgSphere ;
class sgBox ;
class sgFrustum ;
/*
Some handy constants
*/
#define SG_OUTSIDE FALSE
#define SG_INSIDE TRUE
#define SG_STRADDLE 2
inline SGfloat sgHeightOfPlaneVec2 ( const sgVec4 plane, const sgVec2 pnt )
{
if ( plane[2] == SG_ZERO )
return SG_ZERO ;
else
return -( plane[0] * pnt[0] + plane[1] * pnt[1] + plane[3] ) / plane[2] ;
}
/*
Convert a direction vector into a set of euler angles,
(with zero roll)
The direction vector is X-coordinate = north, Y-coordinate = east, Z-coordinate = down
The heading ( = hpr[0] ) is in degrees south of east -- this is VERY nonstandard
The pitch ( = hpr[1] ) is in degrees positive up
The roll ( = hpr[2] ) is zero
*/
extern void sgHPRfromVec3 ( sgVec3 hpr, const sgVec3 src ) ;
extern void sgMakeCoordMat4 ( sgMat4 dst, const SGfloat x, const SGfloat y, const SGfloat z,
const SGfloat h, const SGfloat p, const SGfloat r ) ;
inline void sgMakeCoordMat4( sgMat4 dst, const sgVec3 xyz, const sgVec3 hpr )
{
sgMakeCoordMat4 ( dst, xyz[0], xyz[1], xyz[2],
hpr[0], hpr[1], hpr[2] ) ;
}
inline void sgMakeCoordMat4( sgMat4 dst, const sgCoord *src )
{
sgMakeCoordMat4 ( dst, src->xyz, src->hpr ) ;
}
extern void sgMakeLookAtMat4 ( sgMat4 dst,
const sgVec3 eye, const sgVec3 center, const sgVec3 up ) ;
extern void sgMakeRotMat4 ( sgMat4 dst, const SGfloat angle, const sgVec3 axis ) ;
inline void sgMakeRotMat4 ( sgMat4 dst, const sgVec3 hpr )
{
sgMakeCoordMat4 ( dst, SG_ZERO, SG_ZERO, SG_ZERO, hpr[0], hpr[1], hpr[2] ) ;
}
inline void sgMakeRotMat4 ( sgMat4 dst,const SGfloat h, const SGfloat p, const SGfloat r )
{
sgMakeCoordMat4 ( dst, SG_ZERO, SG_ZERO, SG_ZERO, h, p, r ) ;
}
extern void sgMakeTransMat4 ( sgMat4 dst, const sgVec3 xyz ) ;
extern void sgMakeTransMat4 ( sgMat4 dst, const SGfloat x, const SGfloat y, const SGfloat z ) ;
extern void sgSetCoord ( sgCoord *coord, const sgMat4 src ) ;
extern void sgMultMat4 ( sgMat4 dst, const sgMat4 a, const sgMat4 b ) ;
extern void sgPostMultMat4 ( sgMat4 dst, const sgMat4 a ) ;
extern void sgPreMultMat4 ( sgMat4 dst, const sgMat4 a ) ;
extern void sgTransposeNegateMat4 ( sgMat4 dst ) ;
extern void sgTransposeNegateMat4 ( sgMat4 dst, const sgMat4 src ) ;
extern void sgInvertMat4 ( sgMat4 dst, const sgMat4 src ) ;
inline void sgInvertMat4 ( sgMat4 dst ) { sgInvertMat4 ( dst, dst ) ; }
extern void sgXformVec3 ( sgVec3 dst, const sgVec3 src, const sgMat4 mat ) ;
extern void sgXformPnt3 ( sgVec3 dst, const sgVec3 src, const sgMat4 mat ) ;
extern void sgXformVec4 ( sgVec4 dst, const sgVec4 src, const sgMat4 mat ) ;
extern void sgXformPnt4 ( sgVec4 dst, const sgVec4 src, const sgMat4 mat ) ;
extern void sgFullXformPnt3 ( sgVec3 dst, const sgVec3 src, const sgMat4 mat ) ;
extern void sgFullXformPnt4 ( sgVec4 dst, const sgVec4 src, const sgMat4 mat ) ;
inline void sgXformVec3 ( sgVec3 dst, const sgMat4 mat ) { sgXformVec3 ( dst, dst, mat ) ; }
inline void sgXformPnt3 ( sgVec3 dst, const sgMat4 mat ) { sgXformPnt3 ( dst, dst, mat ) ; }
inline void sgXformVec4 ( sgVec4 dst, const sgMat4 mat ) { sgXformVec4 ( dst, dst, mat ) ; }
inline void sgXformPnt4 ( sgVec4 dst, const sgMat4 mat ) { sgXformPnt4 ( dst, dst, mat ) ; }
inline void sgFullXformPnt3 ( sgVec3 dst, const sgMat4 mat ) { sgFullXformPnt3 ( dst, dst, mat ) ; }
inline void sgFullXformPnt4 ( sgVec4 dst, const sgMat4 mat ) { sgFullXformPnt4 ( dst, dst, mat ) ; }
/* Bits returned by sgClassifyMat4 */
#define SG_IDENTITY 0x00 // for clarity
#define SG_ROTATION 0x01 // includes a rotational component
#define SG_MIRROR 0x02 // changes handedness (det < 0)
#define SG_SCALE 0x04 // uniform scaling
#define SG_NONORTHO 0x10 // 3x3 not orthogonal
#define SG_TRANSLATION 0x20 // translates
#define SG_PROJECTION 0x40 // forth column not 0,0,0,1
/* Are these needed? sgClassifyMat4() does set the general scale bit for some matrices,
* but it is not easily defined. Use SG_NONORTHO instead (which is also set). */
#define SG_UNIFORM_SCALE SG_SCALE
#define SG_GENERAL_SCALE 0x08 // x, y and z scaled differently
extern int sgClassifyMat4 ( const sgMat4 mat ) ;
/*
Basic low-level vector functions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For each of Vec2, Vec3 and Vec4, we provide inlines for
Zero - set all elements to zero.
Set - set each element individually.
Add - add vectors element by element.
Sub - subtract vectors element by element.
Scale - multiply each element of a vector by a variable.
AddScaled
没有合适的资源?快使用搜索试试~ 我知道了~
plib源代码(The PLIB Portable Interactive Applications Library distr...
需积分: 9 17 下载量 3 浏览量
2008-10-26
16:58:03
上传
评论
收藏 761KB GZ 举报
温馨提示
共317个文件
cxx:191个
h:58个
in:15个
WHAT DO YOU GET? The following libraries are provided: JS -- A Joystick interface. PUI -- A simple GUI built on top of OpenGL. SG -- Some Standard Geometry functions (vector and matrix math, spheres, boxes, frustra, etc) SL -- A Games-oriented Sound Library. FNT -- OpenGL texture-mapped font Library. PW -- A minimalist windowing library. PSL -- A C-like scripting language. SSG -- A Simple Scene Graph API built on top of OpenGL. NET -- Some Networking functions for games. UTIL-- Utilities - things that your OS would normally handle - but these functions are portable.
资源推荐
资源详情
资源评论
收起资源包目录
plib源代码(The PLIB Portable Interactive Applications Library distribution) (317个子文件)
TODO-2.0 928B
TODO-1.6 2KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 748B
Makefile.am 514B
Makefile.am 450B
Makefile.am 323B
Makefile.am 313B
Makefile.am 260B
Makefile.am 226B
Makefile.am 224B
Makefile.am 216B
Makefile.am 198B
Makefile.am 60B
AUTHORS 2KB
ChangeLog 34KB
configure 281KB
COPYING 25KB
fntBitmap.cxx 165KB
ssgaLensFlareTexture.cxx 84KB
ssgLoadFLT.cxx 79KB
sgd.cxx 55KB
ssgLoadMDL.cxx 54KB
sg.cxx 54KB
puAuxLargeInput.cxx 43KB
ssgLoadASE.cxx 43KB
ssgLoad3ds.cxx 38KB
ssgLoaderWriterStuff.cxx 30KB
ssgOptimiser.cxx 29KB
ssgaShapes.cxx 28KB
ssgLoadASC.cxx 28KB
ssgLoadVRML1.cxx 27KB
ssgLoadAC.cxx 26KB
pwMacOSX.cxx 26KB
ssgLoadDXF.cxx 25KB
ssgVtxTable.cxx 24KB
puAuxCompass.cxx 23KB
slMODinst.cxx 22KB
slDSP.cxx 22KB
ssgLoadX.cxx 21KB
pslContext.cxx 21KB
ssgVTable.cxx 20KB
ssgSimpleState.cxx 19KB
pslCompiler.cxx 18KB
ssg.cxx 18KB
ssgSaveFLT.cxx 18KB
ssgLoadOBJ.cxx 17KB
puAuxFileSelector.cxx 17KB
pwX11.cxx 17KB
ssgSaveVRML1.cxx 16KB
ssgBranch.cxx 16KB
slScheduler.cxx 15KB
ssgLoadATG.cxx 15KB
ssgLoadDOF.cxx 15KB
slMODfile.cxx 15KB
ssgaCloudLayer.cxx 14KB
ssgSave3ds.cxx 14KB
ssgaSkyDome.cxx 14KB
pwWindows.cxx 14KB
puObject.cxx 14KB
ssgParser.cxx 13KB
jsMacOSX.cxx 13KB
ssgTween.cxx 13KB
ssgLoadSGI.cxx 13KB
slSample.cxx 12KB
puInput.cxx 12KB
jsBSD.cxx 12KB
ssgEntity.cxx 12KB
ul.cxx 12KB
pslToken.cxx 12KB
puGroup.cxx 11KB
ssgVertSplitter.cxx 11KB
pu.cxx 11KB
ssgLoadIV.cxx 11KB
pslExpression.cxx 11KB
ssgVtxArray.cxx 11KB
ssgaTeapot.cxx 10KB
ssgaCelestialBody.cxx 10KB
ssgLoadTGA.cxx 10KB
ssgLoadMDL_BGLTexture.cxx 10KB
ssgLoadXPlaneObj.cxx 10KB
ssgSaveASE.cxx 10KB
ssgaWaveSystem.cxx 10KB
netSocket.cxx 10KB
ssgaSky.cxx 10KB
ssgaLensFlare.cxx 10KB
ssgLoadTexture.cxx 10KB
ssgLoadMD2.cxx 10KB
ssgLoadBMP.cxx 10KB
fntTXF.cxx 10KB
sgIsect.cxx 9KB
ssgStateSelector.cxx 9KB
slMODnote.cxx 9KB
puBox.cxx 9KB
ssgStateTables.cxx 9KB
ssgLoadOFF.cxx 9KB
puAuxComboBox.cxx 9KB
sgdIsect.cxx 9KB
共 317 条
- 1
- 2
- 3
- 4
资源评论
kangsite
- 粉丝: 11
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功