@@ -7,12 +7,12 @@ class DraggerTool :
|
|||||||
public:
|
public:
|
||||||
DraggerTool(void);
|
DraggerTool(void);
|
||||||
~DraggerTool(void);
|
~DraggerTool(void);
|
||||||
void onButton1MouseDown(Mouse);
|
void onButton1MouseDown(Mouse);
|
||||||
void onButton1MouseUp(Mouse);
|
void onButton1MouseUp(Mouse);
|
||||||
void onMouseMoved(Mouse mouse);
|
void onMouseMoved(Mouse mouse);
|
||||||
void onSelect(Mouse mouse);
|
void onSelect(Mouse mouse);
|
||||||
void onKeyDown(int key);
|
void onKeyDown(int key);
|
||||||
void onKeyUp(int key);
|
void onKeyUp(int key);
|
||||||
void render(RenderDevice * rd, Mouse mouse);
|
void render(RenderDevice * rd, Mouse mouse);
|
||||||
private:
|
private:
|
||||||
void createHandles();
|
void createHandles();
|
||||||
@@ -20,5 +20,6 @@ private:
|
|||||||
bool hasHandles;
|
bool hasHandles;
|
||||||
int handleGrabbed;
|
int handleGrabbed;
|
||||||
Vector3 center;
|
Vector3 center;
|
||||||
|
Vector3 CenterOffset;
|
||||||
Sphere handles[6];
|
Sphere handles[6];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "Tool/DraggerTool.h"
|
#include "Tool/DraggerTool.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "DataModelV2/SelectionService.h"
|
#include "DataModelV2/SelectionService.h"
|
||||||
|
|
||||||
DraggerTool::DraggerTool(void)
|
DraggerTool::DraggerTool(void)
|
||||||
@@ -11,123 +11,199 @@ DraggerTool::~DraggerTool(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggerTool::onButton1MouseDown(Mouse mouse)
|
void DraggerTool::onButton1MouseDown(Mouse mouse)
|
||||||
{
|
{
|
||||||
grabHandle(mouse);
|
grabHandle(mouse);
|
||||||
if(handleGrabbed == -1)
|
if(handleGrabbed == -1)
|
||||||
{
|
{
|
||||||
ArrowTool::onButton1MouseDown(mouse);
|
ArrowTool::onButton1MouseDown(mouse);
|
||||||
createHandles();
|
createHandles();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
printf("GRABBED HANDLE!");
|
printf("GRABBED HANDLE!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void DraggerTool::onButton1MouseUp(Mouse mouse)
|
void DraggerTool::onButton1MouseUp(Mouse mouse)
|
||||||
{
|
{
|
||||||
ArrowTool::onButton1MouseUp(mouse);
|
ArrowTool::onButton1MouseUp(mouse);
|
||||||
createHandles();
|
createHandles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggerTool::onMouseMoved(Mouse mouse)
|
void DraggerTool::onMouseMoved(Mouse mouse)
|
||||||
{
|
{
|
||||||
if(handleGrabbed != -1)
|
if(handleGrabbed != -1)
|
||||||
{
|
{
|
||||||
|
std::vector<Instance *> selection = g_dataModel->getSelectionService()->getSelection();
|
||||||
}
|
|
||||||
else ArrowTool::onMouseMoved(mouse);
|
if(selection.size() == 1)
|
||||||
}
|
{
|
||||||
|
PartInstance* part = dynamic_cast<PartInstance*>(selection[0]);
|
||||||
void DraggerTool::onSelect(Mouse mouse)
|
if(part)
|
||||||
{
|
{
|
||||||
ArrowTool::onSelect(mouse);
|
Ray ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().lookVector()*100);
|
||||||
createHandles();
|
|
||||||
}
|
switch(handleGrabbed){
|
||||||
|
case 0:
|
||||||
void DraggerTool::onKeyDown(int key)
|
case 1:
|
||||||
{
|
ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().upVector()*100);
|
||||||
ArrowTool::onKeyDown(key);
|
break;
|
||||||
}
|
case 2:
|
||||||
|
case 3:
|
||||||
void DraggerTool::onKeyUp(int key)
|
ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().lookVector()*100);
|
||||||
{
|
break;
|
||||||
ArrowTool::onKeyUp(key);
|
case 4:
|
||||||
}
|
case 5:
|
||||||
|
ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().leftVector()*100);
|
||||||
void DraggerTool::grabHandle(Mouse mouse)
|
break;
|
||||||
{
|
}
|
||||||
handleGrabbed = -1;
|
|
||||||
if(hasHandles)
|
CenterOffset = handles[handleGrabbed].center;
|
||||||
{
|
|
||||||
G3D::Ray ray = mouse.getRay();
|
Vector3 intersection1 = ray.intersection(mouse.getPlane());
|
||||||
float distance = G3D::inf();
|
Vector3 intersection2 = ray.intersection(mouse.getInversePlane());
|
||||||
for(int i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
float newDistance = ray.intersectionTime(handles[i]);
|
if(intersection1.isFinite())
|
||||||
if(isFinite(newDistance) && newDistance < distance)
|
{
|
||||||
{
|
intersection1.x = (ceil(intersection1.x / 1) * 1);
|
||||||
distance = newDistance;
|
intersection1.y = (ceil(intersection1.y / 1) * 1);
|
||||||
handleGrabbed = i;
|
intersection1.z = (ceil(intersection1.z / 1) * 1);
|
||||||
}
|
|
||||||
}
|
if ( ((int)part->getSize().x)%2 == 1 )
|
||||||
}
|
intersection1.x += 0.5;
|
||||||
}
|
|
||||||
|
//intersection1.y = mouse.getPlane() + part->getSize().y/2 - 0.5;
|
||||||
void DraggerTool::createHandles()
|
|
||||||
{
|
if ( ((int)part->getSize().z)%2 == 1 )
|
||||||
handleGrabbed = -1;
|
intersection1.z += 0.5;
|
||||||
hasHandles = false;
|
|
||||||
std::vector<Instance *> selection = g_dataModel->getSelectionService()->getSelection();
|
part->setPosition(intersection1 + (part->getPosition() - CenterOffset));
|
||||||
if(selection.size() == 1)
|
}
|
||||||
{
|
else if(intersection2.isFinite())
|
||||||
if(PartInstance* part = dynamic_cast<PartInstance*>(selection[0]))
|
{
|
||||||
{
|
intersection2.x = (ceil(intersection2.x / 1) * 1);
|
||||||
hasHandles = true;
|
intersection2.y = (ceil(intersection2.y / 1) * 1);
|
||||||
|
intersection2.z = (ceil(intersection2.z / 1) * 1);
|
||||||
float offset = 2;
|
|
||||||
|
if ( ((int)part->getSize().x)%2 == 1)
|
||||||
center = part->getPosition();
|
intersection2.x += 0.5;
|
||||||
Vector3 size = part->getSize();
|
|
||||||
|
//intersection2.y = mouse.getInversePlane() + part->getSize().y/2 - 0.5;
|
||||||
CoordinateFrame cFrame = part->getCFrame();
|
|
||||||
|
part->setPosition(intersection2 + (part->getPosition() - CenterOffset));
|
||||||
handles[0] = Sphere(center + cFrame.upVector()*(size.y/2+offset), 1);
|
}
|
||||||
handles[1] = Sphere(center - cFrame.upVector()*(size.y/2+offset), 1);
|
|
||||||
|
float offset = 2;
|
||||||
handles[2] = Sphere(center + cFrame.lookVector()*(size.z/2+offset), 1);
|
|
||||||
handles[3] = Sphere(center - cFrame.lookVector()*(size.z/2+offset), 1);
|
center = part->getPosition();
|
||||||
|
Vector3 size = part->getSize();
|
||||||
handles[4] = Sphere(center + cFrame.leftVector()*(size.x/2+offset), 1);
|
CoordinateFrame cFrame = part->getCFrame();
|
||||||
handles[5] = Sphere(center - cFrame.leftVector()*(size.x/2+offset), 1);
|
|
||||||
}
|
handles[0].center = center + cFrame.upVector()*(size.y/2+offset);
|
||||||
}
|
handles[1].center = center - cFrame.upVector()*(size.y/2+offset);
|
||||||
}
|
|
||||||
|
handles[2].center = center + cFrame.lookVector()*(size.z/2+offset);
|
||||||
void DraggerTool::render(RenderDevice * rd, Mouse mouse)
|
handles[3].center = center - cFrame.lookVector()*(size.z/2+offset);
|
||||||
{
|
|
||||||
if(hasHandles)
|
handles[4].center = center + cFrame.leftVector()*(size.x/2+offset);
|
||||||
{
|
handles[5].center = center - cFrame.leftVector()*(size.x/2+offset);
|
||||||
for(int i = 0; i < 6; i++)
|
}
|
||||||
{
|
}
|
||||||
G3D::Draw::arrow(center, handles[i].center-center, rd, Color3::orange(), 2);
|
}
|
||||||
}
|
else ArrowTool::onMouseMoved(mouse);
|
||||||
}
|
}
|
||||||
std::vector<Instance *> selection = g_dataModel->getSelectionService()->getSelection();
|
|
||||||
for(size_t i = 0; i < selection.size(); i++)
|
void DraggerTool::onSelect(Mouse mouse)
|
||||||
{
|
{
|
||||||
if(PartInstance* part = dynamic_cast<PartInstance*>(selection[i]))
|
ArrowTool::onSelect(mouse);
|
||||||
{
|
createHandles();
|
||||||
Ray ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().lookVector()*100);
|
}
|
||||||
Vector3 intersection1 = ray.intersection(mouse.getPlane());
|
|
||||||
Vector3 intersection2 = ray.intersection(mouse.getInversePlane());
|
void DraggerTool::onKeyDown(int key)
|
||||||
if(intersection1.isFinite())
|
{
|
||||||
{
|
ArrowTool::onKeyDown(key);
|
||||||
Draw::sphere(Sphere(intersection1, 2), rd);
|
}
|
||||||
}
|
|
||||||
else if(intersection2.isFinite())
|
void DraggerTool::onKeyUp(int key)
|
||||||
{
|
{
|
||||||
Draw::sphere(Sphere(intersection2, 2), rd);
|
ArrowTool::onKeyUp(key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
void DraggerTool::grabHandle(Mouse mouse)
|
||||||
|
{
|
||||||
|
handleGrabbed = -1;
|
||||||
|
if(hasHandles)
|
||||||
|
{
|
||||||
|
G3D::Ray ray = mouse.getRay();
|
||||||
|
float distance = G3D::inf();
|
||||||
|
for(int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
float newDistance = ray.intersectionTime(handles[i]);
|
||||||
|
if(isFinite(newDistance) && newDistance < distance)
|
||||||
|
{
|
||||||
|
distance = newDistance;
|
||||||
|
handleGrabbed = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DraggerTool::createHandles()
|
||||||
|
{
|
||||||
|
handleGrabbed = -1;
|
||||||
|
hasHandles = false;
|
||||||
|
std::vector<Instance *> selection = g_dataModel->getSelectionService()->getSelection();
|
||||||
|
if(selection.size() == 1)
|
||||||
|
{
|
||||||
|
if(PartInstance* part = dynamic_cast<PartInstance*>(selection[0]))
|
||||||
|
{
|
||||||
|
hasHandles = true;
|
||||||
|
|
||||||
|
float offset = 2;
|
||||||
|
|
||||||
|
center = part->getPosition();
|
||||||
|
Vector3 size = part->getSize();
|
||||||
|
|
||||||
|
CoordinateFrame cFrame = part->getCFrame();
|
||||||
|
|
||||||
|
handles[0] = Sphere(center + cFrame.upVector()*(size.y/2+offset), 1);
|
||||||
|
handles[1] = Sphere(center - cFrame.upVector()*(size.y/2+offset), 1);
|
||||||
|
|
||||||
|
handles[2] = Sphere(center + cFrame.lookVector()*(size.z/2+offset), 1);
|
||||||
|
handles[3] = Sphere(center - cFrame.lookVector()*(size.z/2+offset), 1);
|
||||||
|
|
||||||
|
handles[4] = Sphere(center + cFrame.leftVector()*(size.x/2+offset), 1);
|
||||||
|
handles[5] = Sphere(center - cFrame.leftVector()*(size.x/2+offset), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DraggerTool::render(RenderDevice * rd, Mouse mouse)
|
||||||
|
{
|
||||||
|
if(hasHandles)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
G3D::Draw::arrow(center, handles[i].center-center, rd, Color3::orange(), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Instance *> selection = g_dataModel->getSelectionService()->getSelection();
|
||||||
|
for(size_t i = 0; i < selection.size(); i++)
|
||||||
|
{
|
||||||
|
if(PartInstance* part = dynamic_cast<PartInstance*>(selection[i]))
|
||||||
|
{
|
||||||
|
//Ray ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().lookVector()*100);
|
||||||
|
//Vector3 intersection1 = ray.intersection(mouse.getPlane());
|
||||||
|
//Vector3 intersection2 = ray.intersection(mouse.getInversePlane());
|
||||||
|
//if(intersection1.isFinite())
|
||||||
|
//{
|
||||||
|
// Draw::sphere(Sphere(intersection1, 2), rd);
|
||||||
|
//}
|
||||||
|
//else if(intersection2.isFinite())
|
||||||
|
//{
|
||||||
|
// Draw::sphere(Sphere(intersection2, 2), rd);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user