2

I have a cuboid who's dimensions are imported from XML so i need to be sure that no matter what the size of the model, the camera can always see all of it. This is for preview purposes. I'll likely render a caption over the top showing the scale for clarity.

I think i need some function which will tell me whether the ModelVisual3D fits inside the bounds of the FieldOfView of the camera or maybe the ViewPort3D itself.

So far i have the static callback (the dimension properties are DependencyPropertys) when dimensions properties change define as below. It's pretty crude at the moment but you get the idea I'm looking at. The commented out section shows roughly what kind of logic I'm looking for

    private static void OnCubeDimensionsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (!valueSemaphore)
        {
            //while(mainModel.WillClip(mainCamera))
            //{
            //     mainCamera.FieldOfView--;
            //}

            valueSemaphore = true;
            double propertyValue = 0.0;
            Product3D p = d as Product3D;

            switch (e.Property.Name)
            {
                case "CubeHeight":
                    propertyValue = (double.Parse(e.NewValue.ToString()) / 100) * 8;
                    p.CubeHeight = propertyValue;
                    break;
                case "CubeWidth":
                    propertyValue = (double.Parse(e.NewValue.ToString()) / 100) * 5.3;
                    p.CubeWidth = propertyValue;
                    break;
                case "CubeDepth":
                    propertyValue = (double.Parse(e.NewValue.ToString()) / 100) * 2.6;
                    p.CubeDepth = propertyValue;
                    break;
            }
            valueSemaphore = false;
        }
    }

If anyone knows what should go where the commented-out section is I'd be eternally grateful.
Thanks in advance.

4

1 に答える 1