Merge pull request #2 from andreja6/instances

Merge instances with master
This commit is contained in:
andreja6
2018-04-11 10:19:28 -07:00
committed by GitHub
7 changed files with 240 additions and 11 deletions

Binary file not shown.

View File

@@ -4,6 +4,7 @@
Version="8.00"
Name="G3DTest"
ProjectGUID="{6C4D6EEF-B1D1-456A-B850-92CAB17124BE}"
RootNamespace="G3DTest"
>
<Platforms>
<Platform
@@ -143,14 +144,14 @@
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
RuntimeLibrary="2"
PrecompiledHeaderFile=".\Debug/G3DTest.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@@ -202,12 +203,36 @@
</Configuration>
</Configurations>
<References>
<AssemblyReference
RelativePath="System.dll"
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
/>
<AssemblyReference
RelativePath="System.Data.dll"
AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
/>
<AssemblyReference
RelativePath="System.Drawing.dll"
AssemblyName="System.Drawing, Version=2.0.0.0, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
/>
<AssemblyReference
RelativePath="System.Windows.Forms.dll"
AssemblyName="System.Windows.Forms, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
/>
<AssemblyReference
RelativePath="System.XML.dll"
AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
/>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\Instance.cpp"
>
</File>
<File
RelativePath="main.cpp"
>
@@ -228,11 +253,23 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\PhysicalInstance.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath=".\Instance.h"
>
</File>
<File
RelativePath=".\PhysicalInstance.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"

21
Instance.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <G3DAll.h>
#include "Instance.h"
std::string name;
Instance* parent;
static std::string className = "Instance";
Instance::Instance(void)
{
name = "Default Game Instance";
className = "Part";
}
Instance::~Instance(void)
{
name = "Default Game Instance";
}

11
Instance.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
class Instance
{
public:
Instance(void);
~Instance(void);
std::string name;
Instance* parent; // Another pointer.
std::string className;
};

29
PhysicalInstance.cpp Normal file
View File

@@ -0,0 +1,29 @@
#include <G3DAll.h>
#include "PhysicalInstance.h"
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)
{
}

15
PhysicalInstance.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "instance.h"
class PhysicalInstance :
public Instance
{
public:
PhysicalInstance(void);
~PhysicalInstance(void);
Vector3 size;
Vector3 position;
Vector3 velocity;
Vector3 rotvelocity;
Color3 color;
};

134
main.cpp
View File

@@ -11,12 +11,17 @@
@author Morgan McGuire, matrix@graphics3d.com
*/
#include <G3DAll.h>
#include "Instance.h"
#include "PhysicalInstance.h"
#if G3D_VER < 61000
#error Requires G3D 6.10
#endif
static const float VNUM = 0.01F;
static std::string title = "";
static const std::string VERSION = "PRE-ALPHA ";
static std::vector<Instance*> instances;
static Instance* dataModel;
static GFontRef fntdominant = NULL;
static GFontRef fntlighttrek = NULL;
static bool democ = true;
@@ -88,31 +93,127 @@ 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
dataModel = new Instance();
//dataModel->name = "undefined";
dataModel->parent = NULL;
PhysicalInstance* test = makePart();
test->parent = dataModel;
test->color = Color3(0.2F,0.3F,1);
test->size = Vector3(24,1,24);
test = makePart();
test->parent = dataModel;
test->color = Color3(.5F,1,.5F);
test->size = Vector3(4,1,2);
test->position = Vector3(10,1,0);
test = makePart();
test->parent = dataModel;
test->color = Color3(.5F,1,.5F);
test->size = Vector3(4,1,2);
test->position = Vector3(-10,1,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(-7,2,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(7,2,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(-4,3,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(5,3,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(-1,4,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(3,4,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(2,5,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(0,6,0);
test = makePart();
test->parent = dataModel;
test->color = Color3::gray();
test->size = Vector3(4,1,2);
test->position = Vector3(-2,7,0);
setDesiredFrameRate(FPSVal[index]);
app->debugCamera.setPosition(Vector3(0, 2, 10));
app->debugCamera.lookAt(Vector3(0, 2, 0));
//std::string str = "Dynamica Duomillenium 5 Version " + VERSION + Convert(VNUM);
std::string str = "Game \"undefined\"";
app->renderDevice->setCaption(str);
//title = dataModel->name;
GApplet::onInit();
}
void clearInstances()
{
for(size_t i = 0; i < instances.size(); i++)
delete instances.at(i);
delete dataModel;
}
void OnError(int err, std::string msg = "")
{
std::string emsg = "An unexpected error has occured and DUOM 5 has to quit. We're sorry!" + msg;
clearInstances();
MessageBox(NULL, emsg.c_str(),"Dynamica Crash", MB_OK);
exit(err);
}
void Demo::onCleanup() {
// Called when Demo::run() exits
clearInstances();
}
void Demo::onLogic() {
// Add non-simulation game logic and AI code here
}
@@ -124,7 +225,11 @@ void Demo::onNetwork() {
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
if(dataModel->name != title)
{
title = dataModel->name;
app->renderDevice->setCaption("Game \"" + title + "\"");
}
}
@@ -244,16 +349,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));