Added instance rendering
Added rendering and creation
This commit is contained in:
@@ -3,11 +3,12 @@
|
|||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
Instance* parent;
|
Instance* parent;
|
||||||
static const std::string className = "Instance";
|
static std::string className = "Instance";
|
||||||
|
|
||||||
Instance::Instance(void)
|
Instance::Instance(void)
|
||||||
{
|
{
|
||||||
name = "Default Game Instance";
|
name = "Default Game Instance";
|
||||||
|
className = "Part";
|
||||||
}
|
}
|
||||||
|
|
||||||
Instance::~Instance(void)
|
Instance::~Instance(void)
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ public:
|
|||||||
Instance(void);
|
Instance(void);
|
||||||
~Instance(void);
|
~Instance(void);
|
||||||
std::string name;
|
std::string name;
|
||||||
int getType();
|
|
||||||
Instance* parent; // Another pointer.
|
Instance* parent; // Another pointer.
|
||||||
static const int BASE_INSTANCE;
|
std::string className;
|
||||||
static const int PHYSICAL_INSTANCE;
|
|
||||||
static int type;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
#include <G3DAll.h>
|
#include <G3DAll.h>
|
||||||
#include "PhysicalInstance.h"
|
#include "PhysicalInstance.h"
|
||||||
|
|
||||||
static const std::string className = "Part";
|
|
||||||
bool canCollide = true;
|
bool canCollide = true;
|
||||||
bool anchored = false;
|
bool anchored = false;
|
||||||
Vector3 size;
|
Vector3 size;
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
|
Vector3 velocity;
|
||||||
|
Vector3 rotVelocity;
|
||||||
Color3 color;
|
Color3 color;
|
||||||
|
|
||||||
PhysicalInstance::PhysicalInstance(void)
|
PhysicalInstance::PhysicalInstance(void)
|
||||||
{
|
{
|
||||||
name = "Default PhysicalInstance";
|
name = "Default PhysicalInstance";
|
||||||
|
className = "Part";
|
||||||
canCollide = true;
|
canCollide = true;
|
||||||
anchored = true;
|
anchored = true;
|
||||||
size = Vector3(2,1,4);
|
size = Vector3(2,1,4);
|
||||||
position = Vector3(0,0,0);
|
position = Vector3(0,0,0);
|
||||||
color = Color3::gray();
|
color = Color3::gray();
|
||||||
|
velocity = Vector3(0,0,0);
|
||||||
|
rotVelocity = Vector3(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicalInstance::~PhysicalInstance(void)
|
PhysicalInstance::~PhysicalInstance(void)
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ class PhysicalInstance :
|
|||||||
public:
|
public:
|
||||||
PhysicalInstance(void);
|
PhysicalInstance(void);
|
||||||
~PhysicalInstance(void);
|
~PhysicalInstance(void);
|
||||||
|
Vector3 size;
|
||||||
|
Vector3 position;
|
||||||
|
Vector3 velocity;
|
||||||
|
Vector3 rotvelocity;
|
||||||
|
Color3 color;
|
||||||
};
|
};
|
||||||
|
|||||||
34
main.cpp
34
main.cpp
@@ -92,6 +92,14 @@ std::string Convert (float number){
|
|||||||
return buff.str();
|
return buff.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PhysicalInstance* makePart()
|
||||||
|
{
|
||||||
|
PhysicalInstance* part = new PhysicalInstance();
|
||||||
|
instances.push_back(part);
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
void Demo::onInit() {
|
void Demo::onInit() {
|
||||||
|
|
||||||
// Called before Demo::run() beings
|
// Called before Demo::run() beings
|
||||||
@@ -99,7 +107,11 @@ void Demo::onInit() {
|
|||||||
//dataModel->name = "undefined";
|
//dataModel->name = "undefined";
|
||||||
dataModel->parent = NULL;
|
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]);
|
setDesiredFrameRate(FPSVal[index]);
|
||||||
app->debugCamera.setPosition(Vector3(0, 2, 10));
|
app->debugCamera.setPosition(Vector3(0, 2, 10));
|
||||||
app->debugCamera.lookAt(Vector3(0, 2, 0));
|
app->debugCamera.lookAt(Vector3(0, 2, 0));
|
||||||
@@ -109,6 +121,9 @@ void Demo::onInit() {
|
|||||||
app->renderDevice->setCaption(str);
|
app->renderDevice->setCaption(str);
|
||||||
GApplet::onInit();
|
GApplet::onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void clearInstances()
|
void clearInstances()
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < instances.size(); i++)
|
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);
|
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->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
|
||||||
app->renderDevice->setAmbientLightColor(lighting.ambient);
|
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::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));
|
}
|
||||||
|
//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));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user