1

If I rotate model1, Can I detect the collision model1 and wall1? I can hardly find information about this. Thanks in advance.

wall and stage box cand collide <h:BoxVisual3D Width="4" Height="110" Length="120" Center="15,-50,50" Fill="Gray"/> <ModelVisual3D.Transform> <RotateTransform3D.Rotation> </RotateTransform3D.Rotation> <RotateTransform3D.Rotation> </RotateTransform3D.Rotation> <RotateTransform3D.Rotation> </RotateTransform3D.Rotation> </ModelVisual3D.Transform>

            <!-- "Semi-submersible" -->
            <h:BoxVisual3D Width="120" Height="4" Length="80" Center="10,0,12" Fill="Gray"/>
            <h:BoxVisual3D Width="6" Height="30" Length="6" Center="0,0,24" Fill="Yellow"/>
Sean Ki
  • 11
  • 1

3 Answers3

1

Helix-toolkit doesn't have collision detection, but the code below gives an idea of how to use Visual3DHelper.FindBounds and Rect3D.Intersect to get something close, which might solve your problem.

The problem is that rotating the cube, as commented, may not work perfectly, as the Boundinbox is aligned with the axes, so if the cube is not aligned with the axes, the BoundingBox will be bigger than the cube itself, generating a false positive in the intersection in some cases.

If the wall is aligned with the axis and you don't worry about the cube colliding with the corners of the wall (like an infinite plane), this will work fine even if you rotate the cube.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <StackPanel Margin="5">
        <Slider x:Name="SliderX" Margin="5,10" Minimum="-30" Maximum="30" ValueChanged="Slider1_ValueChanged"/>
        <Slider x:Name="SliderY" Margin="5,10" Minimum="-30" Maximum="30" ValueChanged="Slider1_ValueChanged"/>
    </StackPanel>

    <hx:HelixViewport3D x:Name="MyViewport" Grid.Column="1">

        <hx:DefaultLights/>

        <hx:BoxVisual3D  x:Name="Wall" Height="30" Width="30" Length="1" Fill="Gray" Center="10,0,0"/>

        <hx:BoxVisual3D  x:Name="Object" Height="10" Width="3" Length="10" Fill="Yellow" Center="-10,0,0">
            <hx:BoxVisual3D.Transform>
                <Transform3DGroup>
                    <TranslateTransform3D OffsetX="{Binding ElementName=SliderX, Path=Value}" OffsetY="{Binding ElementName=SliderY, Path=Value}"/>
                    <RotateTransform3D CenterX="-10" CenterY="0" CenterZ="0">
                        <RotateTransform3D.Rotation>
                            <AxisAngleRotation3D Axis="0,0,1" Angle="45"/>
                        </RotateTransform3D.Rotation>
                    </RotateTransform3D>
                </Transform3DGroup>
            </hx:BoxVisual3D.Transform>
        </hx:BoxVisual3D>

    </hx:HelixViewport3D>

</Grid>
private void Slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    var rect1 = Visual3DHelper.FindBounds(Wall, Transform3D.Identity);
    var rect2 = Visual3DHelper.FindBounds(Object, Transform3D.Identity);

    var intersect = Rect3D.Intersect(rect1, rect2);

    if (intersect != Rect3D.Empty)
        Object.Fill = Brushes.Red;
    else
        Object.Fill = Brushes.Blue;
}
dwpessoa
  • 440
  • 4
  • 15
  • Your example illustrates the difficulty with this question and also, why collision detection is not part of Helix/XAML. Collisions depend on the game you're building and many objects in your game. Helix is beautiful tool to create animated 3d UI elements, but if you'd like to do realistic collision detection in a scenery, you'll need to create your objects dynamically, in code behind. To support useful collision involving many objects, you'll need more than a static XAML definition with two objects. Complicated scenery requires collision detect on GPU, which cannot be done with Helix. – Goodies Jun 19 '22 at 10:07
  • @Goodies I don't know why I didn't see your comment before... but yes, you are absolutely right! :) – dwpessoa Oct 07 '22 at 20:08
0

There's no collision detection between meshes in helix toolkit.

Lance H
  • 886
  • 1
  • 9
  • 14
  • We can get some data . getTransform? It seems some kind of position or shape data. but I don't know how to utilize for checking intersection. Do you know about that? – Sean Ki Dec 31 '21 at 05:28
0

Stylize: collide bounding geometries rather than the object itself

Collision detection of arbitrary objects is very complicated, because it depends on the orientation and shape. It also depends on your scenery around: the shape of your base plane and buildings, hills, or other 3d-objects present.

Spheres are easy: colliding spheres you can check by interpolating the distance of mid points during your animation. Calculate momentum and new movement vectors before proceeding the animation.

Colliding two blob objects would involves testing millions of triangles. To prevent that, find a bounding sphere, or bounding rectangle, that moves along with your object. To test for collisions, you test your bounding object rather than the blob itself.

Don't reinvent the wheel

My tip would be: look at the DXVectorMath part of SharpDX. It contains code to find bounding objects and many collision tools written by Christer Ericson. If you don't use SharpDX, consider to isolate DXVectorMath from SharpDX into a separate DLL, convert the Vector3 type to Vector3D and then explore these tools. Don't reinvent the wheel, the math is quite complicated, especially with box shaped objects.

https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Mathematics/Collision.cs

  • This class is organized so that the least complex objects come first so that the least complex objects will have the most methods in most cases. Note that not all shapes exist at this time and not all shapes have a corresponding struct. Only the objects that have a corresponding struct should come first in naming and in parameter order. The order of complexity is as follows:
  • * 1. Point
    * 2. Ray
    * 3. Segment
    * 4. Plane
    * 5. Triangle
    * 6. Polygon
    * 7. Box
    * 8. Sphere
    * 9. Ellipsoid
    * 10. Cylinder
    * 11. Cone
    * 12. Capsule
    * 13. Torus
    * 14. Polyhedron
    * 15. Frustum
    
Goodies
  • 1,951
  • 21
  • 26