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;
Enum::Controller::Value controller;
protected:
CoordinateFrame cFrame;
static G3D::Color3 getControllerColor(int controller)
{
switch(controller)

View File

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

View File

@@ -342,7 +342,7 @@ void eject(PartInstance * colliding, PartInstance * collider)
if(colliding == collider || !colliding->canCollide || !collider->canCollide)
return;
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 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 up = Vector3(0,8,0);
rd->setColor(getControllerColor(controller));
rd->setObjectToWorldMatrix(primaryPart->cFrame);
rd->setObjectToWorldMatrix(primaryPart->getCFrame());
rd->beforePrimitive();
glBegin(GL_LINES);

View File

@@ -5,7 +5,7 @@
#include <iomanip>
PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
PartInstance::PartInstance(void)
{
PVInstance::PVInstance();
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);
glList = glGenLists(1);
@@ -204,11 +204,6 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame)
position = coordinateFrame.translation;
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)
{
@@ -231,16 +226,15 @@ bool PartInstance::collides(PartInstance * part)
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));
CoordinateFrame c = getCFrameRenderBased();
CoordinateFrame c = getCFrame();
itemBox = c.toWorldSpace(box);
return itemBox;
}
Sphere PartInstance::getSphere()
{
Sphere sphere = Sphere(Vector3(0,0,0), size.y/2);
CoordinateFrame c = getCFrameRenderBased();
//itemBox = c.toWorldSpace(Sphere);
return sphere;//itemBox;
CoordinateFrame c = getCFrame();
return sphere;
}
bool PartInstance::collides(Box box)