TEST(Matrix, Scale) { Matrix4 scale; scale.CreateScale(3.0f); Vector3 v(1.0f, 1.0f, 1.0f); v.Transform(scale); EXPECT_NEAR(3.0f, v.GetX(), 0.01f); EXPECT_NEAR(3.0f, v.GetY(), 0.01f); EXPECT_NEAR(3.0f, v.GetZ(), 0.01f); }
void EditorBodyControl::ApplyTransform(float32 x, float32 y, float32 z) { if (!InModificationMode()) return; Entity *selectedNode = scene->GetProxy(); if(selectedNode) { Matrix4 modification; modification.Identity(); Matrix4 t1, t2; t1.CreateTranslation(-selectedNode->GetWorldTransform().GetTranslationVector()); t2.CreateTranslation(selectedNode->GetWorldTransform().GetTranslationVector()); switch (GetModificationMode()) { case ResourceEditor::MODIFY_MOVE: modification.CreateTranslation(Vector3(x, y, z)); break; case ResourceEditor::MODIFY_ROTATE: modification.CreateRotation(Vector3(1, 0, 0), DegToRad(x)); modification *= Matrix4::MakeRotation(Vector3(0, 1, 0), DegToRad(y)); modification *= Matrix4::MakeRotation(Vector3(0, 0, 1), DegToRad(z)); modification = (t1 * modification) * t2; break; case ResourceEditor::MODIFY_SCALE: modification.CreateScale(Vector3(1, 1, 1) + Vector3(x + y + z, x + y + z, x + y + z) / 100.f); modification = (t1 * modification) * t2; break; default: break; } Matrix4 originalTransform = selectedNode->GetLocalTransform(); modification = originalTransform * modification; if (IsLandscapeRelative()) { modification = modification * GetLandscapeOffset(modification); } CommandsManager::Instance()->ExecuteAndRelease(new CommandTransformObject(selectedNode, originalTransform, modification), scene); } }
void EditorBodyControl::PrepareModMatrix(const Vector2 & point) { float32 winx = point.x - touchStart.x; float32 winy = point.y - touchStart.y; Matrix4 modification; modification.Identity(); ArrowsNode* arrowsNode = GetArrowsNode(false); if (!arrowsNode) return; if (GetModificationMode() == ResourceEditor::MODIFY_MOVE) { Vector3 from, dir; GetCursorVectors(&from, &dir, point); Vector3 currPoint; bool result = GetIntersectionVectorWithPlane(from, dir, planeNormal, rotationCenter, currPoint); if (result) { if (arrowsNode) { switch (arrowsNode->GetModAxis()) { case ArrowsNode::AXIS_X: currPoint.y = startDragPoint.y; currPoint.z = startDragPoint.z; break; case ArrowsNode::AXIS_Y: currPoint.x = startDragPoint.x; currPoint.z = startDragPoint.z; break; case ArrowsNode::AXIS_Z: currPoint.x = startDragPoint.x; currPoint.y = startDragPoint.y; break; default: break; } modification.CreateTranslation(currPoint - startDragPoint); } } } else if (GetModificationMode() == ResourceEditor::MODIFY_ROTATE) { Matrix4 d; switch (arrowsNode->GetModAxis()) { case ArrowsNode::AXIS_X: case ArrowsNode::AXIS_Y: modification.CreateRotation(vect[arrowsNode->GetModAxis()], winy / 100.0f); break; case ArrowsNode::AXIS_Z: modification.CreateRotation(vect[arrowsNode->GetModAxis()], winx / 100.0f); break; case ArrowsNode::AXIS_XY: modification.CreateRotation(vect[ArrowsNode::AXIS_X], winx / 100.0f); d.CreateRotation(vect[ArrowsNode::AXIS_Y], winy / 100.0f); modification *= d; break; case ArrowsNode::AXIS_YZ: modification.CreateRotation(vect[ArrowsNode::AXIS_Y], winx / 100.0f); d.CreateRotation(vect[ArrowsNode::AXIS_Z], winy / 100.0f); modification *= d; break; case ArrowsNode::AXIS_XZ: modification.CreateRotation(vect[ArrowsNode::AXIS_X], winx / 100.0f); d.CreateRotation(vect[ArrowsNode::AXIS_Z], winy / 100.0f); modification *= d; break; default: break; } modification = (translate1 * modification) * translate2; } else if (GetModificationMode() == ResourceEditor::MODIFY_SCALE) { float kf = winx / 100.0f; if (kf < -1.0) kf = - kf - 2.0; modification.CreateScale(Vector3(1,1,1) + Vector3(1,1,1) * kf); modification = (translate1 * modification) * translate2; } currTransform = startTransform * modification; }