Merge pull request #38 from Vulpovile/hypersnap-engine

Controllerflags
This commit is contained in:
Vulpovile
2020-03-09 12:02:49 -07:00
committed by GitHub
20 changed files with 513 additions and 33 deletions

View File

@@ -31,7 +31,7 @@
#include "DeleteListener.h" #include "DeleteListener.h"
#include "CameraButtonListener.h" #include "CameraButtonListener.h"
#include "RotateButtonListener.h" #include "RotateButtonListener.h"
#define LEGACY_LOAD_G3DFUN_LEVEL
Ray testRay; Ray testRay;
static int cursorid = 0; static int cursorid = 0;
static int cursorOvrid = 0; static int cursorOvrid = 0;
@@ -167,6 +167,7 @@ void Application::deleteInstance()
g_usableApp->_propWindow->ClearProperties(); g_usableApp->_propWindow->ClearProperties();
} }
void Application::onInit() { void Application::onInit() {
// Called before Application::run() beings // Called before Application::run() beings
@@ -284,16 +285,74 @@ void Application::onCleanup() {
/*
void Application::onLogic() { Class HyperSnapSolver
// Add non-simulation game logic and AI code here
function getCollisionDepth(Part colliding, part collider);
function getFaceCollision(Part colliding, part collider);
function eject(Part colliding, Part collider)
{
if(!colliding.canCollide || !collider.canCollide)
return;
if(getCollisionDepth(colliding, collider) != 0) {
int ejectMultiplier, ejectMultipliery = 1-(collider.Friction+colliding.Friction), ejectMultiplierz = 1-(collider.Friction/2+colliding.Friction/2);
if(colliding.Anchored)
ejectMultiplier = collider.elasticity;
int faceCollided = getFaceCollision(colliding, collider);
if(faceCollided % 3 == 1)
{
ejectMultipliery = ejectMultiplier;
ejectMultiplier = 1-(collider.Friction+colliding.Friction/2);
}
else if(faceCollided % 3 == 2)
{
ejectMultiplierz = ejectMultiplier;
ejectMultiplier = 1-(collider.Friction+colliding.Friction/2);
}
collider.Velocity *= Vector3.new(colliding.Velocity.x*ejectMultiplier,colliding.Velocity.y*ejectMultipliery,colliding.Velocity.z)
}
}
*/
double grav = 0.32666666666666666666666666666667;
void simGrav(PartInstance * collider)
{
if(!collider->anchored)
{
collider->setPosition(collider->getPosition()+collider->getVelocity());
collider->setVelocity(collider->getVelocity()-Vector3(0,grav,0));
}
}
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.3);
} }
void Application::onLogic() {
//PhysicsStart
for_each (_dataModel->getWorkspace()->partObjects.begin(), _dataModel->getWorkspace()->partObjects.end(), simGrav);
for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++)
{
for(size_t j = 0; j < _dataModel->getWorkspace()->partObjects.size(); j++)
{
eject(_dataModel->getWorkspace()->partObjects[i], _dataModel->getWorkspace()->partObjects[j]);
}
}
}
void Application::onNetwork() { void Application::onNetwork() {
// Poll net messages here // Poll net messages here
} }
@@ -310,7 +369,8 @@ std::vector<Instance*> Application::getSelection()
} }
void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
if(_dataModel->isRunning())
onLogic();
_dataModel->getGuiRoot()->update(); _dataModel->getGuiRoot()->update();
@@ -604,7 +664,8 @@ void Application::onGraphics(RenderDevice* rd) {
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
//if(_dataModel->getWorkspace() != NULL) //if(_dataModel->getWorkspace() != NULL)
_dataModel->getWorkspace()->render(rd);
_dataModel->getWorkspace()->render(rd);
//else throw std::exception("Workspace not found"); //else throw std::exception("Workspace not found");
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);

View File

@@ -30,9 +30,19 @@ DataModelInstance::DataModelInstance(void)
level->setParent(this); level->setParent(this);
_loadedFileName="..//skooter.rbxm"; _loadedFileName="..//skooter.rbxm";
listicon = 5; listicon = 5;
running = false;
} }
void DataModelInstance::toggleRun()
{
running = !running;
}
bool DataModelInstance::isRunning()
{
return running;
}
DataModelInstance::~DataModelInstance(void) DataModelInstance::~DataModelInstance(void)
{ {
} }

View File

@@ -36,6 +36,8 @@ public:
bool mouseButton1Down; bool mouseButton1Down;
PartInstance* makePart(); PartInstance* makePart();
void clearLevel(); void clearLevel();
void toggleRun();
bool isRunning();
#if _DEBUG #if _DEBUG
void modXMLLevel(float modY); void modXMLLevel(float modY);
#endif #endif
@@ -51,4 +53,5 @@ private:
WorkspaceInstance* workspace; WorkspaceInstance* workspace;
LevelInstance * level; LevelInstance * level;
GuiRoot* guiRoot; GuiRoot* guiRoot;
bool running;
}; };

6
Enum.h
View File

@@ -14,4 +14,10 @@ namespace Enum
Ball = 0, Block = 1, Cylinder = 2 Ball = 0, Block = 1, Cylinder = 2
}; };
} }
namespace Controller
{
enum Value {
Player = 7, KeyboardRight = 1, KeyboardLeft = 2, Joypad1 = 3, Joypad2 = 4, Chase = 5, Flee = 6, None = 0
};
}
} }

View File

@@ -250,10 +250,6 @@
RelativePath=".\BrowserCallHandler.cpp" RelativePath=".\BrowserCallHandler.cpp"
> >
</File> </File>
<File
RelativePath=".\ButtonListener.cpp"
>
</File>
<File <File
RelativePath=".\CameraController.cpp" RelativePath=".\CameraController.cpp"
> >
@@ -266,14 +262,6 @@
RelativePath=".\Globals.cpp" RelativePath=".\Globals.cpp"
> >
</File> </File>
<File
RelativePath=".\GroupInstance.cpp"
>
</File>
<File
RelativePath=".\GuiRoot.cpp"
>
</File>
<File <File
RelativePath=".\IEBrowser.cpp" RelativePath=".\IEBrowser.cpp"
> >
@@ -314,6 +302,10 @@
RelativePath=".\StringFunctions.cpp" RelativePath=".\StringFunctions.cpp"
> >
</File> </File>
<File
RelativePath=".\ToggleImageButtonInstance.cpp"
>
</File>
<File <File
RelativePath=".\WindowFunctions.cpp" RelativePath=".\WindowFunctions.cpp"
> >
@@ -329,6 +321,14 @@
RelativePath=".\DataModelInstance.cpp" RelativePath=".\DataModelInstance.cpp"
> >
</File> </File>
<File
RelativePath=".\GroupInstance.cpp"
>
</File>
<File
RelativePath=".\GuiRoot.cpp"
>
</File>
<File <File
RelativePath=".\ImageButtonInstance.cpp" RelativePath=".\ImageButtonInstance.cpp"
> >
@@ -361,6 +361,10 @@
<Filter <Filter
Name="Listeners" Name="Listeners"
> >
<File
RelativePath=".\ButtonListener.cpp"
>
</File>
<File <File
RelativePath=".\CameraButtonListener.cpp" RelativePath=".\CameraButtonListener.cpp"
> >
@@ -373,6 +377,10 @@
RelativePath=".\GUDButtonListener.cpp" RelativePath=".\GUDButtonListener.cpp"
> >
</File> </File>
<File
RelativePath=".\MenuButtonListener.cpp"
>
</File>
<File <File
RelativePath=".\ModeSelectionListener.cpp" RelativePath=".\ModeSelectionListener.cpp"
> >
@@ -427,10 +435,6 @@
RelativePath=".\Globals.h" RelativePath=".\Globals.h"
> >
</File> </File>
<File
RelativePath=".\GuiRoot.h"
>
</File>
<File <File
RelativePath=".\IEBrowser.h" RelativePath=".\IEBrowser.h"
> >
@@ -479,6 +483,10 @@
RelativePath=".\StringFunctions.h" RelativePath=".\StringFunctions.h"
> >
</File> </File>
<File
RelativePath=".\ToggleImageButtonInstance.h"
>
</File>
<File <File
RelativePath=".\win32Defines.h" RelativePath=".\win32Defines.h"
> >
@@ -502,6 +510,10 @@
RelativePath=".\GroupInstance.h" RelativePath=".\GroupInstance.h"
> >
</File> </File>
<File
RelativePath=".\GuiRoot.h"
>
</File>
<File <File
RelativePath=".\ImageButtonInstance.h" RelativePath=".\ImageButtonInstance.h"
> >
@@ -546,6 +558,10 @@
RelativePath=".\GUDButtonListener.h" RelativePath=".\GUDButtonListener.h"
> >
</File> </File>
<File
RelativePath=".\MenuButtonListener.h"
>
</File>
<File <File
RelativePath=".\ModeSelectionListener.h" RelativePath=".\ModeSelectionListener.h"
> >

View File

@@ -44,6 +44,10 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
if(g_selectedInstances.at(i)->canDelete) if(g_selectedInstances.at(i)->canDelete)
{ {
g_selectedInstances.at(i)->setParent(inst); g_selectedInstances.at(i)->setParent(inst);
if(PartInstance* part = dynamic_cast<PartInstance*>(g_selectedInstances.at(i)))
{
inst->primaryPart = part;
}
} }
/*tempinst->setPosition(Vector3(tempPos.x, tempPos.y + tempSize.y, tempPos.z)); /*tempinst->setPosition(Vector3(tempPos.x, tempPos.y + tempSize.y, tempPos.z));
g_usableApp->cameraController.centerCamera(g_selectedInstances.at(0));*/ g_usableApp->cameraController.centerCamera(g_selectedInstances.at(0));*/

View File

@@ -6,6 +6,7 @@ GroupInstance::GroupInstance(void)
name = "Model"; name = "Model";
className = "GroupInstance"; className = "GroupInstance";
listicon = 12; listicon = 12;
primaryPart = NULL;
} }
GroupInstance::GroupInstance(const GroupInstance &oinst) GroupInstance::GroupInstance(const GroupInstance &oinst)
@@ -14,6 +15,7 @@ GroupInstance::GroupInstance(const GroupInstance &oinst)
name = "Model"; name = "Model";
className = "GroupInstance"; className = "GroupInstance";
listicon = 12; listicon = 12;
primaryPart = NULL;
} }
GroupInstance::~GroupInstance(void) GroupInstance::~GroupInstance(void)
@@ -39,4 +41,37 @@ std::vector<Instance *> GroupInstance::unGroup()
children[0]->setParent(parent); children[0]->setParent(parent);
} }
return child; return child;
}
void GroupInstance::render(RenderDevice * rd)
{
Instance::render(rd);
if(primaryPart != NULL && controllerFlagShown && getControllerColor(controller) != Color3::gray())
{
rd->disableLighting();
Vector3 vec = Vector3(0,0,0);
Vector3 up = Vector3(0,8,0);
rd->setColor(getControllerColor(controller));
rd->setObjectToWorldMatrix(primaryPart->cFrame);
rd->beforePrimitive();
glBegin(GL_LINES);
glVertex3f(vec.x, vec.y, vec.z);
glVertex3f(up.x, up.y, up.z);
glEnd();
glBegin( GL_TRIANGLES );
glVertex3f(up.x, up.y-2, up.z);
glVertex3f(up.x, up.y-1, up.z-2);
glVertex3f(up.x, up.y, up.z);
glVertex3f(up.x, up.y, up.z);
glVertex3f(up.x, up.y-1, up.z-2);
glVertex3f(up.x, up.y-2, up.z);
glEnd();
rd->afterPrimitive();
rd->setColor(Color3::white());
rd->enableLighting();
}
} }

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "PVInstance.h" #include "PartInstance.h"
class GroupInstance : class GroupInstance :
public PVInstance public PVInstance
@@ -11,4 +11,6 @@ public:
virtual std::vector<PROPGRIDITEM> getProperties(); virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem); virtual void PropUpdate(LPPROPGRIDITEM &pItem);
std::vector<Instance *> unGroup(); std::vector<Instance *> unGroup();
PartInstance * primaryPart;
void render(RenderDevice * r);
}; };

View File

@@ -4,12 +4,14 @@
#include "BaseButtonInstance.h" #include "BaseButtonInstance.h"
#include "TextButtonInstance.h" #include "TextButtonInstance.h"
#include "ImageButtonInstance.h" #include "ImageButtonInstance.h"
#include "ToggleImageButtonInstance.h"
#include "GuiRoot.h" #include "GuiRoot.h"
#include "Globals.h" #include "Globals.h"
#include "StringFunctions.h" #include "StringFunctions.h"
#include "GUDButtonListener.h" #include "GUDButtonListener.h"
#include "ModeSelectionListener.h" #include "ModeSelectionListener.h"
#include "MenuButtonListener.h"
#include "RotateButtonListener.h" #include "RotateButtonListener.h"
#include "CameraButtonListener.h" #include "CameraButtonListener.h"
#include "DeleteListener.h" #include "DeleteListener.h"
@@ -210,10 +212,16 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0)
button->name = "Duplicate"; button->name = "Duplicate";
button->setButtonListener(new GUDButtonListener()); button->setButtonListener(new GUDButtonListener());
ImageButtonInstance* instance = makeImageButton( ImageButtonInstance* instance = new ToggleImageButtonInstance(
Texture::fromFile(GetFileInPath("/content/images/Run.png")), Texture::fromFile(GetFileInPath("/content/images/Run.png")),
Texture::fromFile(GetFileInPath("/content/images/Run_ovr.png")), Texture::fromFile(GetFileInPath("/content/images/Run_ovr.png")),
Texture::fromFile(GetFileInPath("/content/images/Run_dn.png"))); Texture::fromFile(GetFileInPath("/content/images/Run_dn.png")),
NULL,
Texture::fromFile(GetFileInPath("/content/images/Stop.png")),
Texture::fromFile(GetFileInPath("/content/images/Stop_ovr.png")),
Texture::fromFile(GetFileInPath("/content/images/Stop_dn.png"))
);
instance->setButtonListener(new MenuButtonListener());
instance->name = "go"; instance->name = "go";
instance->size = Vector2(65,65); instance->size = Vector2(65,65);
instance->position = Vector2(6.5, 25); instance->position = Vector2(6.5, 25);

View File

@@ -3,6 +3,7 @@
#include "Instance.h" #include "Instance.h"
Instance::Instance(void) Instance::Instance(void)
{ {
parent = NULL; parent = NULL;

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <G3DAll.h> #include <G3DAll.h>
#include "propertyGrid.h" #include "propertyGrid.h"
#include "map"
class Instance class Instance
{ {
@@ -17,7 +18,7 @@ public:
Instance* findFirstChild(std::string); Instance* findFirstChild(std::string);
std::vector<Instance* > getChildren(); std::vector<Instance* > getChildren();
std::vector<Instance* > getAllChildren(); std::vector<Instance* > getAllChildren();
void setParent(Instance*); virtual void setParent(Instance*);
void setName(std::string newName); void setName(std::string newName);
void addChild(Instance*); void addChild(Instance*);
void removeChild(Instance*); void removeChild(Instance*);
@@ -31,5 +32,6 @@ protected:
std::string className; std::string className;
Instance* parent; // Another pointer. Instance* parent; // Another pointer.
PROPGRIDITEM createPGI(LPSTR catalog, LPSTR propName, LPSTR propDesc, LPARAM curVal, INT type, TCHAR choices[] = NULL); PROPGRIDITEM createPGI(LPSTR catalog, LPSTR propName, LPSTR propDesc, LPARAM curVal, INT type, TCHAR choices[] = NULL);
private:
static const std::map<std::string, Instance> g_logLevelsDescriptions;
}; };

11
MenuButtonListener.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include "MenuButtonListener.h"
#include "toggleimagebuttoninstance.h"
#include "Globals.h"
void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button)
{
if(button->name == "go")
{
g_dataModel->toggleRun();
((ToggleImageButtonInstance*)button)->checked = g_dataModel->isRunning();
}
}

8
MenuButtonListener.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include "buttonlistener.h"
class MenuButtonListener :
public ButtonListener
{
public:
void onButton1MouseClick(BaseButtonInstance*);
};

View File

@@ -4,8 +4,10 @@ PVInstance::PVInstance(void)
{ {
Instance::Instance(); Instance::Instance();
nameShown = false; nameShown = false;
controllerFlagShown = true;
className = "PVInstance"; className = "PVInstance";
listicon = 0; listicon = 0;
controller = (Enum::Controller::Value)0;
} }
PVInstance::PVInstance(const PVInstance &oinst) PVInstance::PVInstance(const PVInstance &oinst)
@@ -21,6 +23,46 @@ void PVInstance::postRender(RenderDevice* rd)
{ {
} }
static TCHAR* enumStr(int controller)
{
switch(controller)
{
case Enum::Controller::None:
return "None";
case Enum::Controller::KeyboardLeft:
return "KeyboardLeft";
case Enum::Controller::KeyboardRight:
return "KeyboardRight";
case Enum::Controller::Joypad1:
return "Joypad1";
case Enum::Controller::Joypad2:
return "Joypad2";
case Enum::Controller::Chase:
return "Joypad1";
case Enum::Controller::Flee:
return "Joypad2";
}
}
static Enum::Controller::Value strEnum(TCHAR * tval)
{
if(strcmp(tval, "KeyboardLeft") == 0)
return Enum::Controller::KeyboardLeft;
if(strcmp(tval, "KeyboardRight") == 0)
return Enum::Controller::KeyboardRight;
if(strcmp(tval, "Joypad1") == 0)
return Enum::Controller::Joypad1;
if(strcmp(tval, "Joypad2") == 0)
return Enum::Controller::Joypad2;
if(strcmp(tval, "Chase") == 0)
return Enum::Controller::Chase;
if(strcmp(tval, "Flee") == 0)
return Enum::Controller::Flee;
return Enum::Controller::None;
}
std::vector<PROPGRIDITEM> PVInstance::getProperties() std::vector<PROPGRIDITEM> PVInstance::getProperties()
{ {
std::vector<PROPGRIDITEM> properties = Instance::getProperties(); std::vector<PROPGRIDITEM> properties = Instance::getProperties();
@@ -30,6 +72,21 @@ std::vector<PROPGRIDITEM> PVInstance::getProperties()
"This chooses whether the item name is shown", "This chooses whether the item name is shown",
nameShown, nameShown,
PIT_CHECK)); PIT_CHECK));
properties.push_back(createPGI(
"Item",
"ControllerFlagShown",
"This chooses whether the item's ControllerFlag is shown",
controllerFlagShown,
PIT_CHECK));
properties.push_back(createPGI(
"Behaviour",
"Controller",
"This chooses what type of controller is used",
(LPARAM)enumStr(controller),
PIT_COMBO,
TEXT("None\0KeyboardRight\0KeyboardLeft\0Joypad1\0Joypad2\0Chase\0Flee")
));
return properties; return properties;
} }
void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem) void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem)
@@ -38,5 +95,13 @@ void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{ {
nameShown = (bool)pItem->lpCurValue; nameShown = (bool)pItem->lpCurValue;
} }
if(strcmp(pItem->lpszPropName, "ControllerFlagShown") == 0)
{
controllerFlagShown = (bool)pItem->lpCurValue;
}
if(strcmp(pItem->lpszPropName, "Controller") == 0)
{
controller = strEnum((TCHAR *)pItem->lpCurValue);
}
else Instance::PropUpdate(pItem); else Instance::PropUpdate(pItem);
} }

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "instance.h" #include "instance.h"
#include "enum.h"
class PVInstance : class PVInstance :
public Instance public Instance
@@ -12,4 +13,22 @@ public:
virtual std::vector<PROPGRIDITEM> getProperties(); virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem); virtual void PropUpdate(LPPROPGRIDITEM &pItem);
bool nameShown; bool nameShown;
bool controllerFlagShown;
Enum::Controller::Value controller;
protected:
static G3D::Color3 getControllerColor(int controller)
{
switch(controller)
{
case Enum::Controller::KeyboardLeft:
return Color3::red();
case Enum::Controller::KeyboardRight:
return Color3::blue();
case Enum::Controller::Chase:
return Color3::black();
case Enum::Controller::Flee:
return Color3::yellow();
}
return Color3::gray();
}
}; };

View File

@@ -11,7 +11,7 @@ PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer
name = "Unnamed PVItem"; name = "Unnamed PVItem";
className = "Part"; className = "Part";
canCollide = true; canCollide = true;
anchored = true; anchored = false;
size = Vector3(2,1,4); size = Vector3(2,1,4);
setCFrame(CoordinateFrame(Vector3(0,0,0))); setCFrame(CoordinateFrame(Vector3(0,0,0)));
color = Color3::gray(); color = Color3::gray();
@@ -26,6 +26,25 @@ PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer
shape = Enum::Shape::Block; shape = Enum::Shape::Block;
} }
Vector3 PartInstance::getVelocity()
{
return velocity;
}
Vector3 PartInstance::getRotVelocity()
{
return rotVelocity;
}
void PartInstance::setVelocity(Vector3 v)
{
velocity = v;
}
void PartInstance::setRotVelocity(Vector3 v)
{
rotVelocity = v;
}
void PartInstance::postRender(RenderDevice *rd) void PartInstance::postRender(RenderDevice *rd)
{ {
if(!nameShown) if(!nameShown)
@@ -57,6 +76,30 @@ void PartInstance::postRender(RenderDevice *rd)
} }
} }
void PartInstance::setParent(Instance* parent)
{
Instance * cparent = this->parent;
while(cparent != NULL)
{
if(WorkspaceInstance* workspace = dynamic_cast<WorkspaceInstance*>(parent))
{
workspace->partObjects.erase(std::remove(workspace->partObjects.begin(), workspace->partObjects.end(), this), workspace->partObjects.end());
break;
}
cparent = cparent->getParent();
}
Instance::setParent(parent);
while(parent != NULL)
{
if(WorkspaceInstance* workspace = dynamic_cast<WorkspaceInstance*>(parent))
{
workspace->partObjects.push_back(this);
break;
}
parent = parent->getParent();
}
}
PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0) PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
{ {
PVInstance::PVInstance(oinst); PVInstance::PVInstance(oinst);
@@ -145,7 +188,7 @@ void PartInstance::setShape(Enum::Shape::Value shape)
void PartInstance::setPosition(Vector3 pos) void PartInstance::setPosition(Vector3 pos)
{ {
position = pos; position = pos;
cFrame = CoordinateFrame(pos); cFrame = CoordinateFrame(cFrame.rotation, pos);
changed = true; changed = true;
} }
@@ -1048,6 +1091,11 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
color = Color3(GetRValue(item->lpCurValue)/255.0F,GetGValue(item->lpCurValue)/255.0F,GetBValue(item->lpCurValue)/255.0F); color = Color3(GetRValue(item->lpCurValue)/255.0F,GetGValue(item->lpCurValue)/255.0F,GetBValue(item->lpCurValue)/255.0F);
changed=true; changed=true;
} }
if(strcmp(item->lpszPropName, "Anchored") == 0)
{
anchored=(bool)item->lpCurValue;
changed=true;
}
else if(strcmp(item->lpszPropName, "Offset") == 0) else if(strcmp(item->lpszPropName, "Offset") == 0)
{ {
std::string str = (LPTSTR)item->lpCurValue; std::string str = (LPTSTR)item->lpCurValue;
@@ -1127,8 +1175,14 @@ std::vector<PROPGRIDITEM> PartInstance::getProperties()
RGB((color.r*255),(color.g*255),(color.b*255)), RGB((color.r*255),(color.g*255),(color.b*255)),
PIT_COLOR PIT_COLOR
)); ));
properties.push_back(createPGI(
sprintf_s(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z); "Item",
"Anchored",
"Whether the block can move or not",
(LPARAM)anchored,
PIT_CHECK
));
sprintf_s(pto, "%g, %g, %g", position.x, position.y, position.z);
properties.push_back(createPGI( properties.push_back(createPGI(
"Item", "Item",
"Offset", "Offset",

View File

@@ -16,7 +16,6 @@ public:
virtual void PartInstance::postRender(RenderDevice* rd); virtual void PartInstance::postRender(RenderDevice* rd);
~PartInstance(void); ~PartInstance(void);
virtual void render(RenderDevice*); virtual void render(RenderDevice*);
Vector3 velocity;
Enum::SurfaceType::Value top; Enum::SurfaceType::Value top;
Enum::SurfaceType::Value front; Enum::SurfaceType::Value front;
Enum::SurfaceType::Value right; Enum::SurfaceType::Value right;
@@ -27,7 +26,12 @@ public:
CoordinateFrame cFrame; CoordinateFrame cFrame;
Color3 color; Color3 color;
Vector3 getPosition(); Vector3 getPosition();
Vector3 getVelocity();
Vector3 getRotVelocity();
void setParent(Instance* parent);
void setPosition(Vector3); void setPosition(Vector3);
void setVelocity(Vector3);
void setRotVelocity(Vector3);
CoordinateFrame getCFrame(); CoordinateFrame getCFrame();
void setCFrame(CoordinateFrame); void setCFrame(CoordinateFrame);
Box getBox(); Box getBox();
@@ -38,7 +42,6 @@ public:
void setShape(Enum::Shape::Value shape); void setShape(Enum::Shape::Value shape);
bool canCollide; bool canCollide;
bool anchored; bool anchored;
Vector3 rotVelocity;
bool collides(Box); bool collides(Box);
virtual std::vector<PROPGRIDITEM> getProperties(); virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem); virtual void PropUpdate(LPPROPGRIDITEM &pItem);
@@ -61,6 +64,8 @@ public:
private: private:
Vector3 position; Vector3 position;
Vector3 size; Vector3 size;
Vector3 velocity;
Vector3 rotVelocity;
float _bevelSize; float _bevelSize;
int _parseVert; int _parseVert;
int _debugTimer; int _debugTimer;

View File

@@ -0,0 +1,139 @@
#include "ToggleImageButtonInstance.h"
ToggleImageButtonInstance::ToggleImageButtonInstance(G3D::TextureRef newImage,
G3D::TextureRef overImage,
G3D::TextureRef downImage,
G3D::TextureRef disableImage,
G3D::TextureRef newImage2,
G3D::TextureRef overImage2,
G3D::TextureRef downImage2,
G3D::TextureRef disableImage2) : ImageButtonInstance(newImage, overImage, downImage, disableImage)
{
image2 = newImage2;
openGLID2 = image2->getOpenGLID();
image_ovr2 = overImage2;
if(!image_ovr2.isNull())
openGLID2_ovr = image_ovr2->getOpenGLID();
image_dn2 = downImage2;
if(!image_dn2.isNull())
openGLID2_dn = image_dn2->getOpenGLID();
image_ds2 = disableImage2;
if(!image_ds2.isNull())
openGLID2_ds = image_ds2->getOpenGLID();
checked = false;
className = "ToggleImageButton";
}
ToggleImageButtonInstance::~ToggleImageButtonInstance(void)
{
//Delete everything on destruction
image2.~ReferenceCountedPointer();
delete image2.getPointer();
image_ovr2.~ReferenceCountedPointer();
delete image_ovr2.getPointer();
image_ds2.~ReferenceCountedPointer();
delete image_ds2.getPointer();
image_dn2.~ReferenceCountedPointer();
delete image_dn2.getPointer();
image = NULL;
image_ovr = NULL;
image_ds = NULL;
image_dn = NULL;
delete listener;
listener = NULL;
selected = false;
}
void ToggleImageButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown)
{
bool drawDisabledBox = false;
Vector2 positionRelative = position;
if(floatRight && floatBottom)
{
positionRelative = Vector2(rd->getWidth() + position.x, rd->getHeight() + position.y);
}
else if(floatBottom)
{
positionRelative = Vector2(position.x, rd->getHeight() + position.y);
}
else if(floatRight)
{
positionRelative = Vector2(rd->getWidth() + position.x, position.y);
}
int renderimage = openGLID;
if(checked)
{
renderimage = openGLID2;
if(selected == true && !image_dn2.isNull() && !disabled)
{
renderimage = openGLID2_dn;
}
else if(disabled)
{
if(!image_ds2.isNull())
renderimage = openGLID2_ds;
else
drawDisabledBox = true;
}
else if(mouseInArea(positionRelative.x, positionRelative.y, positionRelative.x + size.x, positionRelative.y + size.y, mousePos.x, mousePos.y))
{
if(mouseDown && !image_dn2.isNull())
{
renderimage = openGLID2_dn;
}
else if(!image_ovr2.isNull())
{
renderimage = openGLID2_ovr;
}
}
}
else
{
if(selected == true && !image_dn.isNull() && !disabled)
{
renderimage = openGLID_dn;
}
else if(disabled)
{
if(!image_ds.isNull())
renderimage = openGLID_ds;
else
drawDisabledBox = true;
}
else if(mouseInArea(positionRelative.x, positionRelative.y, positionRelative.x + size.x, positionRelative.y + size.y, mousePos.x, mousePos.y))
{
if(mouseDown && !image_dn.isNull())
{
renderimage = openGLID_dn;
}
else if(!image_ovr.isNull())
{
renderimage = openGLID_ovr;
}
}
}
glEnable( GL_TEXTURE_2D );
glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture( GL_TEXTURE_2D, renderimage);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f( positionRelative.x, positionRelative.y );
glTexCoord2d( 1.0,0.0 );
glVertex2f( positionRelative.x + size.x, positionRelative.y );
glTexCoord2d( 1.0,1.0 );
glVertex2f( positionRelative.x + size.x, positionRelative.y + size.y );
glTexCoord2d( 0.0,1.0 );
glVertex2f( positionRelative.x, positionRelative.y + size.y );
glEnd();
glDisable( GL_TEXTURE_2D );
if(drawDisabledBox)
{
Draw::box(Box(Vector3(positionRelative.x, positionRelative.y, 0), Vector3(positionRelative.x+size.x, positionRelative.y+size.y, 0)), rd, Color4(0.7F,0.7F,0.7F,0.3F), Color4::clear());
}
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include "imagebuttoninstance.h"
class ToggleImageButtonInstance : public ImageButtonInstance
{
public:
//ImageButtonInstance(G3D::TextureRef);
//ImageButtonInstance(G3D::TextureRef,G3D::TextureRef);
//ImageButtonInstance(G3D::TextureRef,G3D::TextureRef,G3D::TextureRef);
ToggleImageButtonInstance(G3D::TextureRef newImage,G3D::TextureRef overImage = NULL,
G3D::TextureRef downImage = NULL,
G3D::TextureRef disableImage = NULL,
G3D::TextureRef newImage2 = NULL,
G3D::TextureRef overImage2 = NULL,
G3D::TextureRef downImage2 = NULL,
G3D::TextureRef disableImage2 = NULL);
~ToggleImageButtonInstance(void);
void drawObj(RenderDevice*, Vector2, bool);
bool checked;
G3D::TextureRef image2;
int openGLID2;
G3D::TextureRef image_ovr2;
int openGLID2_ovr;
G3D::TextureRef image_dn2;
int openGLID2_dn;
G3D::TextureRef image_ds2;
int openGLID2_ds;
};

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "GroupInstance.h" #include "GroupInstance.h"
#include "PartInstance.h"
class WorkspaceInstance : class WorkspaceInstance :
public GroupInstance public GroupInstance
@@ -7,4 +8,5 @@ class WorkspaceInstance :
public: public:
WorkspaceInstance(void); WorkspaceInstance(void);
~WorkspaceInstance(void); ~WorkspaceInstance(void);
std::vector<PartInstance *> partObjects;
}; };