Made selected a vector
This commit is contained in:
2
Demo.h
2
Demo.h
@@ -16,7 +16,7 @@ class Demo { // : public GApp {
|
|||||||
virtual void onUserInput(UserInput* ui);
|
virtual void onUserInput(UserInput* ui);
|
||||||
virtual void onCleanup();
|
virtual void onCleanup();
|
||||||
|
|
||||||
Instance* getSelection();
|
std::vector<Instance*> getSelection();
|
||||||
void run();
|
void run();
|
||||||
void QuitApp();
|
void QuitApp();
|
||||||
void resizeWithParent(HWND parentWindow);
|
void resizeWithParent(HWND parentWindow);
|
||||||
|
|||||||
43
main.cpp
43
main.cpp
@@ -76,7 +76,7 @@ static int mode = CURSOR;
|
|||||||
bool dragging = false;
|
bool dragging = false;
|
||||||
Vector2 oldMouse = Vector2(0,0);
|
Vector2 oldMouse = Vector2(0,0);
|
||||||
float moveRate = 0.5;
|
float moveRate = 0.5;
|
||||||
Instance* selectedInstance = NULL;
|
std::vector<Instance*> selectedInstances = std::vector<Instance*>();
|
||||||
static const std::string PlaceholderName = "Dynamica";
|
static const std::string PlaceholderName = "Dynamica";
|
||||||
|
|
||||||
Demo *usableApp = NULL;
|
Demo *usableApp = NULL;
|
||||||
@@ -221,8 +221,8 @@ void CameraButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
|||||||
{
|
{
|
||||||
AudioPlayer::playSound(cameraSound);
|
AudioPlayer::playSound(cameraSound);
|
||||||
CoordinateFrame frame = usableApp->cameraController.getCamera()->getCoordinateFrame();
|
CoordinateFrame frame = usableApp->cameraController.getCamera()->getCoordinateFrame();
|
||||||
if(button->name == "CenterCam")
|
if(button->name == "CenterCam" && selectedInstances.size() > 0)
|
||||||
usableApp->cameraController.centerCamera(selectedInstance);
|
usableApp->cameraController.centerCamera(selectedInstances.at(0));
|
||||||
else if(button->name == "ZoomIn")
|
else if(button->name == "ZoomIn")
|
||||||
usableApp->cameraController.Zoom(1);
|
usableApp->cameraController.Zoom(1);
|
||||||
else if(button->name == "ZoomOut")
|
else if(button->name == "ZoomOut")
|
||||||
@@ -244,7 +244,7 @@ public:
|
|||||||
|
|
||||||
void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
||||||
{
|
{
|
||||||
if(selectedInstance != NULL)
|
if(selectedInstances.size() > 0)
|
||||||
{
|
{
|
||||||
AudioPlayer::playSound(dingSound);
|
AudioPlayer::playSound(dingSound);
|
||||||
if(button->name == "Duplicate")
|
if(button->name == "Duplicate")
|
||||||
@@ -262,8 +262,9 @@ public:
|
|||||||
|
|
||||||
void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
||||||
{
|
{
|
||||||
if(selectedInstance != NULL)
|
if(selectedInstances.size() > 0)
|
||||||
{
|
{
|
||||||
|
Instance* selectedInstance = selectedInstances.at(0);
|
||||||
AudioPlayer::playSound(clickSound);
|
AudioPlayer::playSound(clickSound);
|
||||||
if(selectedInstance->getClassName() == "Part")
|
if(selectedInstance->getClassName() == "Part")
|
||||||
{
|
{
|
||||||
@@ -273,6 +274,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
|||||||
else if(button->name == "Rotate")
|
else if(button->name == "Rotate")
|
||||||
part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,toRadians(90),0));
|
part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,toRadians(90),0));
|
||||||
}
|
}
|
||||||
|
selectedInstances.erase(selectedInstances.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -280,14 +282,19 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
|||||||
|
|
||||||
void deleteInstance()
|
void deleteInstance()
|
||||||
{
|
{
|
||||||
if(selectedInstance != NULL)
|
if(selectedInstances.size() > 0)
|
||||||
{
|
{
|
||||||
|
while(selectedInstances.size() > 0)
|
||||||
|
{
|
||||||
|
Instance* selectedInstance = selectedInstances.at(0);
|
||||||
if(selectedInstance->getParent() != NULL)
|
if(selectedInstance->getParent() != NULL)
|
||||||
selectedInstance->getParent()->removeChild(selectedInstance);
|
selectedInstance->getParent()->removeChild(selectedInstance);
|
||||||
delete selectedInstance;
|
delete selectedInstance;
|
||||||
selectedInstance = NULL;
|
selectedInstance = NULL;
|
||||||
|
selectedInstances.erase(selectedInstances.begin());
|
||||||
AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav"));
|
AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -788,7 +795,7 @@ void Demo::onLogic() {
|
|||||||
if(obj != NULL)
|
if(obj != NULL)
|
||||||
{
|
{
|
||||||
ImageButtonInstance* button = (ImageButtonInstance*)obj;
|
ImageButtonInstance* button = (ImageButtonInstance*)obj;
|
||||||
if(selectedInstance == NULL)
|
if(selectedInstances.size() > 0)
|
||||||
button->disabled = true;
|
button->disabled = true;
|
||||||
else
|
else
|
||||||
button->disabled = false;
|
button->disabled = false;
|
||||||
@@ -808,9 +815,9 @@ void Demo::onNetwork() {
|
|||||||
// return pow(pow((double)vector1.x - (double)vector2.x, 2) + pow((double)vector1.y - (double)vector2.y, 2) + pow((double)vector1.z - (double)vector2.z, 2), 0.5);
|
// return pow(pow((double)vector1.x - (double)vector2.x, 2) + pow((double)vector1.y - (double)vector2.y, 2) + pow((double)vector1.z - (double)vector2.z, 2), 0.5);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Instance* Demo::getSelection()
|
std::vector<Instance*> Demo::getSelection()
|
||||||
{
|
{
|
||||||
return selectedInstance;
|
return selectedInstances;
|
||||||
}
|
}
|
||||||
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
||||||
if(dataModel->name != title)
|
if(dataModel->name != title)
|
||||||
@@ -875,7 +882,9 @@ void Demo::onUserInput(UserInput* ui) {
|
|||||||
|
|
||||||
if (GetHoldKeyState(VK_LBUTTON)) {
|
if (GetHoldKeyState(VK_LBUTTON)) {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
PhysicalInstance* part = (PhysicalInstance*) selectedInstance;
|
PhysicalInstance* part = NULL;
|
||||||
|
if(selectedInstances.size() > 0)
|
||||||
|
part = (PhysicalInstance*) selectedInstances.at(0);
|
||||||
Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
||||||
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
||||||
for(size_t i = 0; i < instances.size(); i++)
|
for(size_t i = 0; i < instances.size(); i++)
|
||||||
@@ -1117,13 +1126,16 @@ void Demo::onGraphics(RenderDevice* rd) {
|
|||||||
dataModel->getWorkspace()->render(rd);
|
dataModel->getWorkspace()->render(rd);
|
||||||
rd->afterPrimitive();
|
rd->afterPrimitive();
|
||||||
|
|
||||||
if(selectedInstance != NULL)
|
if(selectedInstances.size() > 0)
|
||||||
{
|
{
|
||||||
PhysicalInstance* part = (PhysicalInstance*)selectedInstance;
|
for(size_t i = 0; i < selectedInstances.size(); i++)
|
||||||
|
{
|
||||||
|
PhysicalInstance* part = (PhysicalInstance*)selectedInstances.at(i);
|
||||||
Vector3 size = part->getSize();
|
Vector3 size = part->getSize();
|
||||||
Vector3 pos = part->getPosition();
|
Vector3 pos = part->getPosition();
|
||||||
drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
|
drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Vector3 gamepoint = Vector3(0, 5, 0);
|
//Vector3 gamepoint = Vector3(0, 5, 0);
|
||||||
@@ -1236,7 +1248,8 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y)
|
|||||||
}
|
}
|
||||||
if(!onGUI)
|
if(!onGUI)
|
||||||
{
|
{
|
||||||
selectedInstance = NULL;
|
while(selectedInstances.size() > 0)
|
||||||
|
selectedInstances.erase(selectedInstances.begin());
|
||||||
testRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
testRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
||||||
float nearest=std::numeric_limits<float>::infinity();
|
float nearest=std::numeric_limits<float>::infinity();
|
||||||
Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation;
|
Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation;
|
||||||
@@ -1252,7 +1265,9 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y)
|
|||||||
if (nearest>time)
|
if (nearest>time)
|
||||||
{
|
{
|
||||||
nearest=time;
|
nearest=time;
|
||||||
selectedInstance = test;
|
while(selectedInstances.size() > 0)
|
||||||
|
selectedInstances.erase(selectedInstances.begin());
|
||||||
|
selectedInstances.push_back(test);
|
||||||
//message = "Dragging = true.";
|
//message = "Dragging = true.";
|
||||||
//messageTime = System::time();
|
//messageTime = System::time();
|
||||||
//dragging = true;
|
//dragging = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user