Cleaned up partinstance.h, moved CFrame to PVInstance

This commit is contained in:
Vulpovile
2021-03-13 22:18:25 -08:00
parent 3963dd5286
commit 2a6d90ad66
5 changed files with 35 additions and 37 deletions

View File

@@ -16,6 +16,7 @@ public:
bool controllerFlagShown; bool controllerFlagShown;
Enum::Controller::Value controller; Enum::Controller::Value controller;
protected: protected:
CoordinateFrame cFrame;
static G3D::Color3 getControllerColor(int controller) static G3D::Color3 getControllerColor(int controller)
{ {
switch(controller) switch(controller)

View File

@@ -4,18 +4,20 @@
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <cmath> #include <cmath>
#define NEW_BOX_RENDER
class PartInstance : public PVInstance class PartInstance : public PVInstance
{ {
public: public:
PartInstance(void); PartInstance(void);
PartInstance(const PartInstance &oinst); PartInstance(const PartInstance &oinst);
Instance* clone() const { return new PartInstance(*this); }
virtual void PartInstance::postRender(RenderDevice* rd);
~PartInstance(void); ~PartInstance(void);
Instance* clone() const { return new PartInstance(*this); }
//Rendering
virtual void PartInstance::postRender(RenderDevice* rd);
virtual void render(RenderDevice*); virtual void render(RenderDevice*);
//Surfaces
Enum::SurfaceType::Value top; Enum::SurfaceType::Value top;
Enum::SurfaceType::Value front; Enum::SurfaceType::Value front;
Enum::SurfaceType::Value right; Enum::SurfaceType::Value right;
@@ -23,42 +25,43 @@ public:
Enum::SurfaceType::Value left; Enum::SurfaceType::Value left;
Enum::SurfaceType::Value bottom; Enum::SurfaceType::Value bottom;
Enum::Shape::Value shape; Enum::Shape::Value shape;
CoordinateFrame cFrame;
//Variables
Color3 color; Color3 color;
bool canCollide;
bool anchored;
//Getters
Vector3 getPosition(); Vector3 getPosition();
Vector3 getVelocity(); Vector3 getVelocity();
Vector3 getRotVelocity(); Vector3 getRotVelocity();
void setParent(Instance* parent); Vector3 getSize();
void setPosition(Vector3);
void setVelocity(Vector3);
bool collides(PartInstance * part);
void setRotVelocity(Vector3);
CoordinateFrame getCFrame();
void setCFrame(CoordinateFrame);
Box getBox(); Box getBox();
Sphere getSphere(); Sphere getSphere();
Box getScaledBox(); Box getScaledBox();
CoordinateFrame getCFrameRenderBased(); CoordinateFrame getCFrame();
Vector3 getSize();
//Setters
void setParent(Instance* parent);
void setPosition(Vector3);
void setVelocity(Vector3);
void setRotVelocity(Vector3);
void setCFrame(CoordinateFrame);
void setSize(Vector3); void setSize(Vector3);
void setShape(Enum::Shape::Value shape); void setShape(Enum::Shape::Value shape);
bool canCollide;
bool anchored; //Collision
bool collides(PartInstance * part);
bool collides(Box); bool collides(Box);
//Properties
virtual std::vector<PROPGRIDITEM> getProperties(); virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem); virtual void PropUpdate(LPPROPGRIDITEM &pItem);
#ifdef NEW_BOX_RENDER
void addPlus(Vector3 v1);
void addPlus2(Vector3 v1);
#endif
private: private:
Vector3 position; Vector3 position;
Vector3 size; Vector3 size;
Vector3 velocity; Vector3 velocity;
Vector3 rotVelocity; Vector3 rotVelocity;
float _bevelSize;
int _parseVert;
int _debugTimer;
bool changed; bool changed;
Box itemBox; Box itemBox;
GLuint glList; GLuint glList;

View File

@@ -342,7 +342,7 @@ void eject(PartInstance * colliding, PartInstance * collider)
if(colliding == collider || !colliding->canCollide || !collider->canCollide) if(colliding == collider || !colliding->canCollide || !collider->canCollide)
return; return;
if(G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(collider->getBox(), colliding->getBox())) if(G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(collider->getBox(), colliding->getBox()))
collider->setVelocity(collider->getVelocity().reflectionDirection(colliding->cFrame.upVector())/1.3F); collider->setVelocity(collider->getVelocity().reflectionDirection(colliding->getCFrame().upVector())/1.3F);
} }
@@ -718,7 +718,7 @@ void Application::onGraphics(RenderDevice* rd) {
{ {
Vector3 size = part->getSize(); Vector3 size = part->getSize();
Vector3 pos = part->getPosition(); Vector3 pos = part->getPosition();
drawOutline(Vector3(0+size.x/2, 0+size.y/2, 0+size.z/2) ,Vector3(0-size.x/2,0-size.y/2,0-size.z/2), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x, pos.y, pos.z), part->getCFrameRenderBased()); drawOutline(Vector3(0+size.x/2, 0+size.y/2, 0+size.z/2) ,Vector3(0-size.x/2,0-size.y/2,0-size.z/2), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x, pos.y, pos.z), part->getCFrame());
} }
} }
} }

View File

@@ -52,7 +52,7 @@ void GroupInstance::render(RenderDevice * rd)
Vector3 vec = Vector3(0,0,0); Vector3 vec = Vector3(0,0,0);
Vector3 up = Vector3(0,8,0); Vector3 up = Vector3(0,8,0);
rd->setColor(getControllerColor(controller)); rd->setColor(getControllerColor(controller));
rd->setObjectToWorldMatrix(primaryPart->cFrame); rd->setObjectToWorldMatrix(primaryPart->getCFrame());
rd->beforePrimitive(); rd->beforePrimitive();
glBegin(GL_LINES); glBegin(GL_LINES);

View File

@@ -5,7 +5,7 @@
#include <iomanip> #include <iomanip>
PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0) PartInstance::PartInstance(void)
{ {
PVInstance::PVInstance(); PVInstance::PVInstance();
glList = glGenLists(1); glList = glGenLists(1);
@@ -102,7 +102,7 @@ void PartInstance::setParent(Instance* prnt)
} }
} }
PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0) PartInstance::PartInstance(const PartInstance &oinst)
{ {
PVInstance::PVInstance(oinst); PVInstance::PVInstance(oinst);
glList = glGenLists(1); glList = glGenLists(1);
@@ -204,11 +204,6 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame)
position = coordinateFrame.translation; position = coordinateFrame.translation;
changed = true; changed = true;
} }
// Can probably be deleted
CoordinateFrame PartInstance::getCFrameRenderBased()
{
return cFrame;//CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z));
}
bool PartInstance::collides(PartInstance * part) bool PartInstance::collides(PartInstance * part)
{ {
@@ -231,16 +226,15 @@ bool PartInstance::collides(PartInstance * part)
Box PartInstance::getBox() Box PartInstance::getBox()
{ {
Box box = Box(Vector3(size.x/2, size.y/2, size.z/2) ,Vector3(-size.x/2,-size.y/2,-size.z/2)); Box box = Box(Vector3(size.x/2, size.y/2, size.z/2) ,Vector3(-size.x/2,-size.y/2,-size.z/2));
CoordinateFrame c = getCFrameRenderBased(); CoordinateFrame c = getCFrame();
itemBox = c.toWorldSpace(box); itemBox = c.toWorldSpace(box);
return itemBox; return itemBox;
} }
Sphere PartInstance::getSphere() Sphere PartInstance::getSphere()
{ {
Sphere sphere = Sphere(Vector3(0,0,0), size.y/2); Sphere sphere = Sphere(Vector3(0,0,0), size.y/2);
CoordinateFrame c = getCFrameRenderBased(); CoordinateFrame c = getCFrame();
//itemBox = c.toWorldSpace(Sphere); return sphere;
return sphere;//itemBox;
} }
bool PartInstance::collides(Box box) bool PartInstance::collides(Box box)