Merge branch 'develop' of github.com:Vulpovile/G3D-Fun into feature/physics_improvements_and_optimizations
This commit is contained in:
@@ -13,6 +13,7 @@ public:
|
||||
void onSelect(Mouse mouse);
|
||||
void onKeyDown(int key);
|
||||
void onKeyUp(int key);
|
||||
void roundDeg(float °ree);
|
||||
private:
|
||||
bool lctrlDown;
|
||||
bool rctrlDown;
|
||||
@@ -20,4 +21,5 @@ private:
|
||||
int mouseDownStarty;
|
||||
bool dragging;
|
||||
bool mouseDown;
|
||||
Vector3 draggingPartOffset;
|
||||
};
|
||||
|
||||
@@ -242,6 +242,12 @@ void PartInstance::setPosition(Vector3 pos)
|
||||
{
|
||||
position = pos;
|
||||
setCFrame(CoordinateFrame(cFrame.rotation, pos));
|
||||
|
||||
if (anchored)
|
||||
{
|
||||
g_dataModel->getEngine()->deleteBody(this);
|
||||
g_dataModel->getEngine()->createBody(this);
|
||||
}
|
||||
}
|
||||
|
||||
void PartInstance::setAnchored(bool anchored)
|
||||
|
||||
@@ -25,7 +25,13 @@ void ArrowTool::onButton1MouseDown(Mouse mouse)
|
||||
g_dataModel->getSelectionService()->clearSelection();
|
||||
PartInstance * target = mouse.getTarget();
|
||||
if(target != NULL)
|
||||
{
|
||||
Vector3 mousePos = mouse.getPosition(g_dataModel->getSelectionService()->getSelection());
|
||||
Vector3 targetPos = target->getPosition();
|
||||
|
||||
g_dataModel->getSelectionService()->addSelected(target);
|
||||
draggingPartOffset = targetPos-mousePos;
|
||||
}
|
||||
if(g_dataModel->getSelectionService()->getSelection().size() == 0)
|
||||
g_dataModel->getSelectionService()->addSelected(g_dataModel);
|
||||
}
|
||||
@@ -51,7 +57,40 @@ void ArrowTool::onMouseMoved(Mouse mouse)
|
||||
{
|
||||
if(PartInstance * part = dynamic_cast<PartInstance *>(g_dataModel->getSelectionService()->getSelection()[i]))
|
||||
{
|
||||
part->setPosition(mouse.getPosition(g_dataModel->getSelectionService()->getSelection()));
|
||||
Vector3 mousePos = mouse.getPosition(g_dataModel->getSelectionService()->getSelection());
|
||||
Vector3 vec = mousePos + draggingPartOffset;
|
||||
|
||||
vec.x = (ceil(vec.x / 1) * 1);
|
||||
vec.y = (ceil(vec.y / 1) * 1);
|
||||
vec.z = (ceil(vec.z / 1) * 1);
|
||||
|
||||
if ( ((int)part->getSize().x)%2 == 1 )
|
||||
vec.x += 0.5;
|
||||
|
||||
vec.y = mousePos.y + part->getSize().y/2 - 0.5;
|
||||
|
||||
if ( ((int)part->getSize().z)%2 == 1 )
|
||||
vec.z += 0.5;
|
||||
|
||||
Matrix3 rot = part->getCFrame().rotation;
|
||||
Vector3 rotEulerAngles;
|
||||
|
||||
rot.toEulerAnglesXYZ(rotEulerAngles.x, rotEulerAngles.y, rotEulerAngles.z);
|
||||
|
||||
rotEulerAngles = Vector3(
|
||||
rotEulerAngles.x * 180 / M_PI,
|
||||
rotEulerAngles.y * 180 / M_PI,
|
||||
rotEulerAngles.z * 180 / M_PI
|
||||
);
|
||||
|
||||
roundDeg(rotEulerAngles.x);
|
||||
roundDeg(rotEulerAngles.y);
|
||||
roundDeg(rotEulerAngles.z);
|
||||
|
||||
rot = rot.fromEulerAnglesXYZ( rotEulerAngles.x * (M_PI / 180), rotEulerAngles.y * (M_PI / 180), rotEulerAngles.z * (M_PI / 180) );
|
||||
|
||||
part->setPosition(vec);
|
||||
part->setCFrame(CoordinateFrame(rot, vec));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -76,3 +115,19 @@ void ArrowTool::onKeyUp(int key)
|
||||
if(key == VK_CONTROL)
|
||||
lctrlDown = false;
|
||||
}
|
||||
|
||||
void ArrowTool::roundDeg(float °ree)
|
||||
{
|
||||
if ( ( degree < 0 && degree > -45 ) || ( degree > 0 && degree < 45 ) )
|
||||
{
|
||||
degree = 0;
|
||||
}
|
||||
else if ( ( degree < 0 && degree > -90 ) || ( degree > 45 && degree < 90 ) )
|
||||
{
|
||||
degree = 90;
|
||||
}
|
||||
else if ( ( degree < 0 && degree > -180 ) || ( degree > 90 && degree < 180 ) )
|
||||
{
|
||||
degree = 180;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user