I'm trying to implement a 2D Grid in a simple 3D Editor. Here are some debug-rays I already implemented:
Everything is working as intended as long as the object is not rotated. For demonstration purpose the box is aligned with the grid center (the purple box).
Now if I rotate the large white cube I want the grid to rotate as well.
Here is the problem: I dont want the origin of the grid to change it's relativ location. The grid location of the green line should still align with the upper left corner of the large white box.
And I just cannot figure out the offset I have to translate the grid :(
Here is what I've tried: Calculate the difference between the two collision points (Yellow and Green) and use this as offset but on rotation the offset is too large and the grid is shifting.
Here is the data I have available:
Vector3 Origin = new Vector3(); Vector3 GridPlaneNormal = new Vector3(0, 0, 1); Plane GridPlane = new Plane(Origin, GridPlaneNormal); Plane objectPlane = /*.... (it's the plane of the cubes front)*/ Vector3 GridNormalInDirectionOfObject = Vector3.TransformNormal(GridPlaneNormal, Matrix.RotationQuaternion(Object.RotationQuaternion)); float angle = GridPlaneNormal.SignedAngle(GridNormalInDirectionOfObject, GridPlane.Normal); Vector3 rotationAxis = Vector3.Normalize(Vector3.Cross(GridPlane.Normal, objectPlane.Normal));
Please help me! :)