Added instance rendering

Added rendering and creation
This commit is contained in:
andreja6
2018-04-11 08:56:54 -07:00
parent 7d38523166
commit 58ee5c9889
5 changed files with 44 additions and 12 deletions

View File

@@ -3,11 +3,12 @@
std::string name;
Instance* parent;
static const std::string className = "Instance";
static std::string className = "Instance";
Instance::Instance(void)
{
name = "Default Game Instance";
className = "Part";
}
Instance::~Instance(void)

View File

@@ -6,9 +6,6 @@ public:
Instance(void);
~Instance(void);
std::string name;
int getType();
Instance* parent; // Another pointer.
static const int BASE_INSTANCE;
static const int PHYSICAL_INSTANCE;
static int type;
std::string className;
};

View File

@@ -1,22 +1,25 @@
#include <G3DAll.h>
#include "PhysicalInstance.h"
static const std::string className = "Part";
bool canCollide = true;
bool anchored = false;
Vector3 size;
Vector3 position;
Vector3 velocity;
Vector3 rotVelocity;
Color3 color;
PhysicalInstance::PhysicalInstance(void)
{
name = "Default PhysicalInstance";
className = "Part";
canCollide = true;
anchored = true;
size = Vector3(2,1,4);
position = Vector3(0,0,0);
color = Color3::gray();
velocity = Vector3(0,0,0);
rotVelocity = Vector3(0,0,0);
}
PhysicalInstance::~PhysicalInstance(void)

View File

@@ -7,4 +7,9 @@ class PhysicalInstance :
public:
PhysicalInstance(void);
~PhysicalInstance(void);
Vector3 size;
Vector3 position;
Vector3 velocity;
Vector3 rotvelocity;
Color3 color;
};

View File

@@ -92,6 +92,14 @@ std::string Convert (float number){
return buff.str();
}
PhysicalInstance* makePart()
{
PhysicalInstance* part = new PhysicalInstance();
instances.push_back(part);
return part;
}
void Demo::onInit() {
// Called before Demo::run() beings
@@ -99,7 +107,11 @@ void Demo::onInit() {
//dataModel->name = "undefined";
dataModel->parent = NULL;
Instance* test = new PhysicalInstance();
PhysicalInstance* test = makePart();
test->parent = dataModel;
test->color = Color3(0.2,0.7,0.3);
test->size = Vector3(128,1,128);
setDesiredFrameRate(FPSVal[index]);
app->debugCamera.setPosition(Vector3(0, 2, 10));
app->debugCamera.lookAt(Vector3(0, 2, 0));
@@ -109,6 +121,9 @@ void Demo::onInit() {
app->renderDevice->setCaption(str);
GApplet::onInit();
}
void clearInstances()
{
for(size_t i = 0; i < instances.size(); i++)
@@ -260,16 +275,27 @@ void Demo::onGraphics(RenderDevice* rd) {
Draw::axes(CoordinateFrame(Vector3(0, 0, 0)), app->renderDevice);
makeFlag(Vector3(1, 0.5, 0.5), rd);
//makeFlag(Vector3(1, 0.5, 0.5), rd);
app->renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
app->renderDevice->setAmbientLightColor(lighting.ambient);
Draw::box(G3D::Box(Vector3(4.0/2,1.0/2,2.0/2),Vector3(0,0,0)), rd, Color3::gray(), Color4(0,0,0,0));
Draw::cylinder(G3D::Cylinder::Cylinder(Vector3(0,5,0),Vector3(0,10,0),1),app->renderDevice,Color4(0,0,1,0.5),Color4(0,0,0,0));
//Draw::box(G3D::Box(Vector3(4.0/2,1.0/2,2.0/2),Vector3(0,0,0)), rd, Color3::gray(), Color4(0,0,0,0));
for(size_t i = 0; i < instances.size(); i++)
{
Instance* instance = instances.at(i);
if(instance->className == "Part" && instance->parent != NULL)
{
PhysicalInstance* part = (PhysicalInstance*)instance;
Vector3 size = part->size;
Vector3 pos = part->position;
Draw::box(Box(Vector3((pos.x-size.x/2)/2,(pos.y-size.y/2)/2,(pos.z-size.z/2)/2),Vector3((pos.x+size.x/2)/2,(pos.y+size.y/2)/2,(pos.z+size.z/2)/2)), app->renderDevice, part->color, Color4::clear());
}
}
//Draw::cylinder(G3D::Cylinder::Cylinder(Vector3(0,5,0),Vector3(0,10,0),1),app->renderDevice,Color4(0,0,1,0.5),Color4(0,0,0,0));