WPF 3D Rotation Point - wpf

I have a 3D object that I'm rotating in WPF.
I need to know how to move the point that the object is rotating on. Currently my object rotates from the 0,0,0. I'd like to be able to change the the point of rotation to 50,0,0 (or any other point I set).

The solution was to set the RotateTransform3D CenterX, CenterY, or CenterZ parameter to account for the offset where you want the rotation to happen.

Related

Three-react-fiber Setting the rotation axis to the centre of the model

I have a model which rotates on the X axis, but the center of the rotation is not on the axis itself. The rotation code is pretty simple:
model.current.rotation.x += 0.016; (axis and speed)
but there seems no way to define the actual axis of rotation to ensure the model just rotates around its own center. At the moment it rotates in a big circle!
Any suggestions appreciated.
:-0
your mesh most likely is not centred, meaning the vertices point way out of the models center of mass. you can either fix this in blender, but even threejs has methods (on the geometry) that recalculate the vertices. a cheaper solution would be to render the mesh, take a box3, set it from the object, then get min/max and use it to shift the object by half of it.

Rotate Camera in the Direction behind object in OpenGL

I'm making a game in OpenGL, using freeglut.
I have a car, which I am able to move back and forward using keys and the camera follows it. Now, when I turn the car(glRotate in xz plane), I want the camera to change the Camera position(using gluLookAt) so it always points to the back of the car.
Any suggestions how do I do that?
For camera follow I use the object transform matrix
get object transform matrix
camera=object
use glGetMatrix or whatever for that
shift rotate the position so Z axis is directing where you want to look
I use object aligned to forward on Z axis, but not all mesh models are like this so rotate by (+/-)90 deg around x,y or z to match this:
Z-axis is forward (or backward depends on your projection matrix and depth function)
X-axis is Right
Y-axis is Up
with respect to your camera/screen coordinate system (projection matrix). Then translate to behind position
apply POV rotation (optional)
if you can slightly rotate camera view from forward direction (mouse look) then do it at this step
camera*=rotation_POV
convert matrix to camera
camera matrix is usually inverse of the coordinate system matrix it represents so:
camera=Inverse(camera)
For more info look here understanding transform matrices the OpenGL inverse matrix computation in C++ is included there.

object not rotating properly after translate transform in wpf?

I have canvas with several cutom controls inherited from panel class, dynamically added to it at runtime with rendertransform=(.5,.5). But when apply translate transform (50,50) and rotate it by 100 degrees, it does not rotate on its place, it rotates in radius of 50, why?
Am I doing wrong something ?
Transformations are not commutative, you should apply the rotation before applying the translation.
Often you have a TransformGroup, then you can just change the order of its children, if this is somehow not an option because some transform is "inherited" from a parent you can nullify prior transforms using their inverse (in the case of a translation that should move the target back to the origin), then you can rotate it in place, and apply the original transform again.
The documentation is your friend, here is what can be found for TransformGroups:
In a composite transformation, the order of individual transformations is important. For example, if you first rotate, then scale, then translate, you get a different result than if you first translate, then rotate, then scale. One reason order is significant is that transformations like rotation and scaling are done with respect to the origin of the coordinate system. Scaling an object that is centered at the origin produces a different result than scaling an object that has been moved away from the origin. Similarly, rotating an object that is centered at the origin produces a different result than rotating an object that has been moved away from the origin.
If it rotates with a radius of 50, it's because your origin is wrong.
You just need to change the origin of your RotateTransform by setting the CenterX and CenterY properties both to 50 in this case.

Getting Relative Position of a Rotating Camera

I have a Viewport3D with a 3D model composed of multiple smaller components centered at the origin. I'm animating the PerspectiveCamera to rotate about the Y-axis using an AnimationClock created from a DoubleAnimation to create a rotating effect on the model. In addition, I have another rotateTransform3D assigned to the camera's transformgroup to enable the user to orbit around and zoom in-out of the model using the mouse.
I want to be able to translate each component as it is being selected to move in front of the rotating camera. However, I don't know how to get the position of the camera relative to the 3D model because the coordinate system of camera is being animated and transformed by the user's input.
Is there a way to get the offset between two coordinate systems?
Any help or suggestions would be appreciated.
Thanks,

WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25).
When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)...
How can I achieve this?
Thanks!
Mark
Just use VisualTreeHelper.HitTest with the callback.
If you have a Viewport3D containing the model, you can just pass in a PointHitTestParameters containing the mouse location.
If you need to operate directly on a Visual3D, pass in a RayHitTestParameters computed from your camera parameters and the mouse location.
In either case your callback will be called with a RayTestHitResult, and if you hit a mesh it will be a RayMeshGeometry3DHitTestResult. This includes a Point3D property telling you the 3D point in space that was hit, and also the mesh and triangle that was hit.
See 3D Hit testing for more details.

Resources