@@ -20,5 +20,6 @@ private:
|
||||
bool hasHandles;
|
||||
int handleGrabbed;
|
||||
Vector3 center;
|
||||
Vector3 CenterOffset;
|
||||
Sphere handles[6];
|
||||
};
|
||||
|
||||
@@ -33,7 +33,82 @@ void DraggerTool::onMouseMoved(Mouse mouse)
|
||||
{
|
||||
if(handleGrabbed != -1)
|
||||
{
|
||||
std::vector<Instance *> selection = g_dataModel->getSelectionService()->getSelection();
|
||||
|
||||
if(selection.size() == 1)
|
||||
{
|
||||
PartInstance* part = dynamic_cast<PartInstance*>(selection[0]);
|
||||
if(part)
|
||||
{
|
||||
Ray ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().lookVector()*100);
|
||||
|
||||
switch(handleGrabbed){
|
||||
case 0:
|
||||
case 1:
|
||||
ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().upVector()*100);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().lookVector()*100);
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
ray = G3D::Ray::fromOriginAndDirection(part->getPosition(), part->getCFrame().leftVector()*100);
|
||||
break;
|
||||
}
|
||||
|
||||
CenterOffset = handles[handleGrabbed].center;
|
||||
|
||||
Vector3 intersection1 = ray.intersection(mouse.getPlane());
|
||||
Vector3 intersection2 = ray.intersection(mouse.getInversePlane());
|
||||
|
||||
|
||||
if(intersection1.isFinite())
|
||||
{
|
||||
intersection1.x = (ceil(intersection1.x / 1) * 1);
|
||||
intersection1.y = (ceil(intersection1.y / 1) * 1);
|
||||
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;
|
||||
|
||||
if ( ((int)part->getSize().z)%2 == 1 )
|
||||
intersection1.z += 0.5;
|
||||
|
||||
part->setPosition(intersection1 + (part->getPosition() - CenterOffset));
|
||||
}
|
||||
else if(intersection2.isFinite())
|
||||
{
|
||||
intersection2.x = (ceil(intersection2.x / 1) * 1);
|
||||
intersection2.y = (ceil(intersection2.y / 1) * 1);
|
||||
intersection2.z = (ceil(intersection2.z / 1) * 1);
|
||||
|
||||
if ( ((int)part->getSize().x)%2 == 1)
|
||||
intersection2.x += 0.5;
|
||||
|
||||
//intersection2.y = mouse.getInversePlane() + part->getSize().y/2 - 0.5;
|
||||
|
||||
part->setPosition(intersection2 + (part->getPosition() - CenterOffset));
|
||||
}
|
||||
|
||||
float offset = 2;
|
||||
|
||||
center = part->getPosition();
|
||||
Vector3 size = part->getSize();
|
||||
CoordinateFrame cFrame = part->getCFrame();
|
||||
|
||||
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);
|
||||
handles[3].center = center - cFrame.lookVector()*(size.z/2+offset);
|
||||
|
||||
handles[4].center = center + cFrame.leftVector()*(size.x/2+offset);
|
||||
handles[5].center = center - cFrame.leftVector()*(size.x/2+offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
else ArrowTool::onMouseMoved(mouse);
|
||||
}
|
||||
@@ -112,22 +187,23 @@ void DraggerTool::render(RenderDevice * rd, Mouse mouse)
|
||||
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);
|
||||
}
|
||||
//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