atomic world bounding sphere

This commit is contained in:
aap 2016-02-18 14:56:10 +01:00
parent 7be2e634fe
commit 9bc57a0641
3 changed files with 33 additions and 13 deletions

5
TODO
View File

@ -2,14 +2,9 @@ BUGS:
- fseek with negative offset on ps2 over ps2link messes up the current position - fseek with negative offset on ps2 over ps2link messes up the current position
Clump & related: Clump & related:
- make pointer arrays into lists
- !!! work on ref counts, destruction, copying etc. - !!! work on ref counts, destruction, copying etc.
- define and use types: - define and use types:
sphere
matrix
color color
realcolor
vector3
triangle triangle
texcoord texcoord
- implement plugins: - implement plugins:

View File

@ -568,14 +568,14 @@ Atomic::create(void)
assert(atomic != NULL); assert(atomic != NULL);
atomic->object.init(Atomic::ID, 0); atomic->object.init(Atomic::ID, 0);
atomic->geometry = NULL; atomic->geometry = NULL;
atomic->worldBoundingSphere.center.set(0.0f, 0.0f, 0.0f);
atomic->worldBoundingSphere.radius = 0.0f;
atomic->setFrame(NULL);
atomic->clump = NULL; atomic->clump = NULL;
atomic->pipeline = NULL; atomic->pipeline = NULL;
atomic->renderCB = Atomic::defaultRenderCB; atomic->renderCB = Atomic::defaultRenderCB;
atomic->object.flags = Atomic::COLLISIONTEST | Atomic::RENDER; atomic->object.flags = Atomic::COLLISIONTEST | Atomic::RENDER;
atomic->constructPlugins(); atomic->constructPlugins();
// private flags:
// rpATOMICPRIVATEWORLDBOUNDDIRTY = 0x01
return atomic; return atomic;
} }
@ -606,6 +606,22 @@ Atomic::destroy(void)
free(this); free(this);
} }
Sphere*
Atomic::getWorldBoundingSphere(void)
{
Sphere *s = &this->worldBoundingSphere;
if(!this->getFrame()->dirty() &&
(this->object.privateFlags & WORLDBOUNDDIRTY) == 0)
return s;
Matrix *ltm = this->getFrame()->getLTM();
// TODO: support scaling
s->center = ltm->transPoint(s->center);
// TODO: if we ever support morphing, fix this:
s->radius = this->geometry->morphTargets[0].boundingSphere.radius;
this->object.privateFlags &= ~WORLDBOUNDDIRTY;
return s;
}
static uint32 atomicRights[2]; static uint32 atomicRights[2];
Atomic* Atomic*

View File

@ -119,6 +119,8 @@ struct Frame : PluginBase<Frame>
Frame *getParent(void){ Frame *getParent(void){
return (Frame*)this->object.parent; } return (Frame*)this->object.parent; }
int32 count(void); int32 count(void);
bool32 dirty(void) {
return !!(this->root->object.privateFlags & HIERARCHYSYNC); }
Matrix *getLTM(void); Matrix *getLTM(void);
void updateObjects(void); void updateObjects(void);
@ -558,11 +560,14 @@ struct Atomic : PluginBase<Atomic>
enum { ID = 1 }; enum { ID = 1 };
enum { enum {
COLLISIONTEST = 0x01, // unused here COLLISIONTEST = 0x01, // unused here
RENDER = 0x04 RENDER = 0x04,
// private
WORLDBOUNDDIRTY = 0x01
}; };
ObjectWithFrame object; ObjectWithFrame object;
Geometry *geometry; Geometry *geometry;
Sphere worldBoundingSphere;
Clump *clump; Clump *clump;
LLLink inClump; LLLink inClump;
ObjPipeline *pipeline; ObjPipeline *pipeline;
@ -571,17 +576,21 @@ struct Atomic : PluginBase<Atomic>
static Atomic *create(void); static Atomic *create(void);
Atomic *clone(void); Atomic *clone(void);
void destroy(void); void destroy(void);
void setFrame(Frame *f) { this->object.setFrame(f); } void setFrame(Frame *f) {
this->object.setFrame(f);
this->object.privateFlags |= WORLDBOUNDDIRTY;
}
Frame *getFrame(void) { return (Frame*)this->object.parent; } Frame *getFrame(void) { return (Frame*)this->object.parent; }
static Atomic *fromClump(LLLink *lnk){ static Atomic *fromClump(LLLink *lnk){
return LLLinkGetData(lnk, Atomic, inClump); } return LLLinkGetData(lnk, Atomic, inClump); }
ObjPipeline *getPipeline(void);
Sphere *getWorldBoundingSphere(void);
static Atomic *streamReadClump(Stream *stream, static Atomic *streamReadClump(Stream *stream,
Frame **frameList, Geometry **geometryList); Frame **frameList, Geometry **geometryList);
void render(void) { this->renderCB(this); }
bool streamWriteClump(Stream *stream, bool streamWriteClump(Stream *stream,
Frame **frameList, int32 numframes); Frame **frameList, int32 numframes);
uint32 streamGetSize(void); uint32 streamGetSize(void);
ObjPipeline *getPipeline(void);
void render(void) { this->renderCB(this); }
static void defaultRenderCB(Atomic *atomic); static void defaultRenderCB(Atomic *atomic);
}; };