简体   繁体   中英

3D graphics in wpf c# on windows

I am new to 3d Graphics and also wpf and need to combine these two in my current project. I add points and normals to MeshGeometry3D and add MeshGeometry3D to GeometryModel3D . Then add GeometryModel3D to ModelVisual3D and finally add ModelVisual3D to ViewPort3D . Now if i need to rotate i perform the required Transform either on GeometryModel3D or ModelVisual3D and add it again finally to the ViewPort3D. I'm running into a problems:

objViewPort3D.Remove(objModelVisual3D);
objGeometryModel3D.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), angle += 15));
objModelVisual3D.Content = objGeometryModel3D;
objViewPort3D.Children.Add(objModelVisual3D);

to rotate it everytime by 15 degrees why must i do angle += 15 and not just 15 ? It seems that the stored model is not transformed by Transform operation but transformation is applied only when displaying by ViewPort3D . I want the transformation to actually change the coordinates in the stored MeshGeometry3D object so that when i do the transform next time it does on the previously transformed model and not the original model. How do i obtain this behaviour?

I think you can use Animation

some pseudo-code:

angle = 0 function onClick: new_angle = angle + 30 Animate(angle, new_angle) angle = new_angle

Correct, the position of the mesh is not transformed by the "Transform" operation. Instead the Transform property defines the world transform of the mesh during rendering.

In 3d graphics the world transform transforms the points of the mesh from object space to world space during the render of the object.

对象空间到世界空间图

(Image from World, View and Projection Matrix Unveiled )

It's much faster to set the world transform and let the renderer draw the mesh in a single transform than transforming each vertex of a mesh, like you want.

You have to do angle += 15 because you're applying a new RotateTransform3D each time.

This might help:

public RotateTransform3D MyRotationTransform { get; set; }
...
//constructor
public MyClass()
{
     MyRotationTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0));

}

//in your method
MyRotationTransform.Rotation += 15;
objGeometryModel3D.Transform = MyRotationTransform;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM