diff --git a/src/camera.cpp b/src/camera.cpp index c68ef01..a1b4575 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -355,6 +355,21 @@ Camera::setFarPlane(float32 far) calczShiftScale(this); } +int32 +Camera::frustumTestSphere(Sphere *s) +{ + int32 res = SPHEREINSIDE; + FrustumPlane *p = this->frustumPlanes; + for(int32 i = 0; i < 6; i++){ + float32 dist = dot(p->plane.normal, s->center) - p->plane.distance; + if(s->radius < dist) + return SPHEREOUTSIDE; + if(s->radius > -dist) + res = SPHEREBOUNDARY; + } + return res; +} + struct CameraChunkData { V2d viewWindow; diff --git a/src/geometry.cpp b/src/geometry.cpp index 6e87f7b..3989222 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -105,6 +105,7 @@ Geometry::streamRead(Stream *stream) GeoStreamData buf; SurfaceProperties surfProps; MaterialList *ret; + static SurfaceProperties reset = { 1.0f, 1.0f, 1.0f }; if(!findChunk(stream, ID_STRUCT, nil, &version)){ RWERROR((ERR_CHUNK, "STRUCT")); @@ -154,7 +155,7 @@ Geometry::streamRead(Stream *stream) defaultSurfaceProps = surfProps; ret = MaterialList::streamRead(stream, &geo->matList); if(version < 0x34000) - defaultSurfaceProps = (SurfaceProperties){ 1.0f, 1.0f, 1.0f }; + defaultSurfaceProps = reset; if(ret == nil) goto fail; if(s_plglist.streamRead(stream, geo)) diff --git a/src/rwbase.h b/src/rwbase.h index 0f8b4f3..85b64a0 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -2,6 +2,9 @@ #include #endif #include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif #ifdef RW_GL3 #define RW_OPENGL diff --git a/src/rwobjects.h b/src/rwobjects.h index 3ee0cee..508ae31 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -572,6 +572,8 @@ struct Camera : PluginBase enum { ID = 4 }; enum { PERSPECTIVE = 1, PARALLEL }; enum { CLEARIMAGE = 0x1, CLEARZ = 0x2}; + // return value of frustumTestSphere + enum { SPHEREOUTSIDE, SPHEREBOUNDARY, SPHEREINSIDE }; ObjectWithFrame object; void (*beginUpdateCB)(Camera*); @@ -612,6 +614,7 @@ struct Camera : PluginBase void clear(RGBA *col, uint32 mode); void setNearPlane(float32); void setFarPlane(float32); + int32 frustumTestSphere(Sphere *s); static Camera *streamRead(Stream *stream); bool streamWrite(Stream *stream); uint32 streamGetSize(void);