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
Clump & related:
- make pointer arrays into lists
- !!! work on ref counts, destruction, copying etc.
- define and use types:
sphere
matrix
color
realcolor
vector3
triangle
texcoord
- implement plugins:

View File

@ -568,14 +568,14 @@ Atomic::create(void)
assert(atomic != NULL);
atomic->object.init(Atomic::ID, 0);
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->pipeline = NULL;
atomic->renderCB = Atomic::defaultRenderCB;
atomic->object.flags = Atomic::COLLISIONTEST | Atomic::RENDER;
atomic->constructPlugins();
// private flags:
// rpATOMICPRIVATEWORLDBOUNDDIRTY = 0x01
return atomic;
}
@ -606,6 +606,22 @@ Atomic::destroy(void)
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];
Atomic*

View File

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