Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Transform a model's positions directly

Transform a model's positions directly

Scheduled Pinned Locked Moved WPF
questioncsharpwpfarchitecturetutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Frank Boettcher
    wrote on last edited by
    #1

    Hi; I'm new to WPF, and I'm trying to understand the underlying architecture, so please correct me if I'm wrong: As far as I know, there are three possibilities to dynamically transform a GeometryModel3D during runtime: a) Set the model's Transform-property to a Transform3DGroup once, to which you add new / duplicate Transformations. b) Cast the model's Transform-property as a MatrixTransform3D and multiply its matrix with the Value-property of a Transformation (which i guess is pretty much case (a) ) c) Leave the Transform-property as a identity matrix and instead transform the model's Geometry.Positions property directly (provided you use a MeshGeometry3D) like such:

    int i;
    MeshGeometry3D mesh;

    mesh = (_SomeModel.Geometry as MeshGeometry3D);
    for (i = 0; i < mesh.Positions.Count; i++)
    {
    mesh.Positions[i] = _SomeTransform.Transform(
    mesh.Positions[i]);
    }

    On first glance, option (c) seems like the best (though not most intuitive) choice, especially when you need the actual positions of the model(s); for example to calculate hit-detection. Is there another way to easily access a model's current, transformed position(s)? And why does WPF transform a model's own space instead of just the actual coordinates? Kind regards, Frank

    K 1 Reply Last reply
    0
    • F Frank Boettcher

      Hi; I'm new to WPF, and I'm trying to understand the underlying architecture, so please correct me if I'm wrong: As far as I know, there are three possibilities to dynamically transform a GeometryModel3D during runtime: a) Set the model's Transform-property to a Transform3DGroup once, to which you add new / duplicate Transformations. b) Cast the model's Transform-property as a MatrixTransform3D and multiply its matrix with the Value-property of a Transformation (which i guess is pretty much case (a) ) c) Leave the Transform-property as a identity matrix and instead transform the model's Geometry.Positions property directly (provided you use a MeshGeometry3D) like such:

      int i;
      MeshGeometry3D mesh;

      mesh = (_SomeModel.Geometry as MeshGeometry3D);
      for (i = 0; i < mesh.Positions.Count; i++)
      {
      mesh.Positions[i] = _SomeTransform.Transform(
      mesh.Positions[i]);
      }

      On first glance, option (c) seems like the best (though not most intuitive) choice, especially when you need the actual positions of the model(s); for example to calculate hit-detection. Is there another way to easily access a model's current, transformed position(s)? And why does WPF transform a model's own space instead of just the actual coordinates? Kind regards, Frank

      K Offline
      K Offline
      Kubajzz
      wrote on last edited by
      #2

      I don't think (c) seems like the best option, although there are some scenarious where it might be appropriate to transform each vertex (or "position") directly... The Transform property is there for a reason. You can move, rotate, scale etc. the entire model by setting just one matrix. That's far easier than transforming each vertex. There is also a good reasony why WPF stores the positions relative to the model's coordinate system. This is actually how almost every CAD program and 3D engine works. Most of the time when you are editing the shape of a model you don't really care how the model is oriented and transformed, because you only pay attention to the shape itself, that's why relative coordinates are useful. You can always get the global coordinates easily by using the model's transformation matrix. One more thing: moving each vertex of the model might be a lot slower than transforming the whole model at once. It depends on the implementation of the 3D engine, but if you set the Transform property of the model, the transformation of all vertices might be hardware accelerated, while transforming each vertex individually will definitely run on the CPU. I can't answer your question ("which method is the best") because it depends on your application... But I would try to avoid option (c).

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups