xBimTeam / XbimWindowsUI

The home of XbimXplorer and WPF components for your desktop BIM applications.
Other
253 stars 151 forks source link

Initialized CameraPosition #7

Closed LitsaM closed 9 years ago

LitsaM commented 9 years ago

Hi again,

I am trying to set a default camera position for the model but I can't find how. I first added this code:

    // The camera.
    private PerspectiveCamera TheCamera;

    // The camera's current location.
    private double CameraPhi = Math.PI / 6.0;       // 30 degrees
    private double CameraTheta = Math.PI / 6.0;     // 30 degrees
    private double CameraR = 3.0;

TheCamera = new PerspectiveCamera();
        TheCamera.FieldOfView = 100;
        DrawingControl.SetCamera(TheCamera);
        PositionCamera();

private void PositionCamera()
    {
        // Calculate the camera's position in Cartesian coordinates.
        double y = CameraR * Math.Sin(CameraPhi);
        double hyp = CameraR * Math.Cos(CameraPhi);
        double x = hyp * Math.Cos(CameraTheta);
        double z = hyp * Math.Sin(CameraTheta);
        TheCamera.Position = new Point3D(x, y, z);

        // Look toward the origin.
        TheCamera.LookDirection = new Vector3D(-x, -y, -z);

        // Set the Up direction.
        TheCamera.UpDirection = new Vector3D(0, 1, 0);
    }

And didn't work so then I added this (after I deleted everything from above):

        // Defines the camera used to view the 3D object. In order to view the 3D object, 
        // the camera must be positioned and pointed such that the object is within view  
        // of the camera.
        PerspectiveCamera myPCamera = new PerspectiveCamera();

        // Specify where in the 3D scene the camera is.
        myPCamera.Position = new Point3D(0, 0, 2);

        // Specify the direction that the camera is pointing.
        myPCamera.LookDirection = new Vector3D(0, 0, -1);

        // Define camera's horizontal field of view in degrees.
        myPCamera.FieldOfView = 60;

        // Asign the camera to the viewport
        myViewport3D.Camera = myPCamera;

<Viewport3D x:Name="myViewport3D">
        <!-- Add a camera. -->
        <Viewport3D.Camera>
            <PerspectiveCamera FarPlaneDistance="20" LookDirection="5,-2,-3" UpDirection="0,1,0"  NearPlaneDistance="1" Position="-5,2,3" FieldOfView="45" />
        </Viewport3D.Camera>
    </Viewport3D>

...

But then I figured out that they changed the camera podition but when my program opens the model, then the camera position changes. I don't know how to explain that so you can understand but I guess that after opening the model there is somewhere in the project that they give an initial or default matrix for the view of the model or the camera positions of viewing the model. But I can't find where is that so I can change it.

LitsaM commented 9 years ago

Ok so I figured it out. I should add the position after the model was loaded, so I tried to find that part and I found out that its here

namespace Xbim.Presentation
{
    public static  class Rect3DExtensions
    {
        public static XbimRect3D ToXbimRect3D(this Rect3D r3D)
        {
            return new XbimRect3D(r3D.X, r3D.Y, r3D.Z, r3D.SizeX, r3D.SizeY, r3D.SizeZ);
        }
    }
}

So by adding numbers instead of variables r3D.X etc I can change the position of the mode. But I have a question. what "r3D.SizeX, r3D.SizeY, r3D.SizeZ" do? I mean what do they change if I change them. I did some experiments, I did see some changes but I can't understand what they do exactly.

kazmaier commented 9 years ago

Hi Litsa. I will try to take a deeper look at this issue over the weekend and see if I have any feedback for you - just been busy with work over the past few days. :)

Andy

LitsaM commented 9 years ago

Ok Andy thank you so much :)

CBenghi commented 9 years ago

Hi Litsa, sorry for the long delay, we had a few things to sort out before being able to respond to this. There have been changes in the camera/zooming code.

The comments below relate to the develop branch of the code... Master will follow in a bit. Or if you are using Nuget packages then update from https://www.myget.org/F/xbim-develop/api/v2 including pre-releases.

I'm not sure about the context in which you are trying to achieve a different zooming behaviour, so I'll try to be generic, but feel free to post again to add details.

Ok, so if you wish to set a camera different from the default at runtime after load you should use the .SetCamera() function of the viewer. Your code would likely build a suitable camera, just pass that. For any guidance on cameras you might want to look at the Helix Toolkit documentation disregarding r3d (described below, anyway).

If you are using the viewer component in your code you might want to change the behaviour of the default zoom. For this I've just marked the ViewHome() function Virtual so you can now override it and take control of the default zoom behaviour.

Rect3D is basically a bounding box with position and size, position being the min coordinate over each axis and size the difference between the max and min coordinates; _viewBounds contains the bounding box for all loaded models (you can load multiple models using a federation) and it transforms the scene in meters as unit (each model is scaled according to its unit defaults if needed). ModelPositions contains information about the scaling of models if you need to transform the coordinate of the camera according to their transform.

Viewport.ZoomExtents(r3D); is a native HelixToolkit call, so you'll find the documentation there, however you can remove that call and use your custom camera in your override.

I hope this helps, but I'd be happy to give any other help more swiftly this time around.

CBenghi commented 9 years ago

I'm closing the issue, feel free to write again if it needs refining.

LitsaM commented 9 years ago

Hi Claudio. I am sorry for not replying I was busy and I just saw your messages. Thank you very much for your reply, I have stopped working with my project but I hope I will be back in 2 months, I'll check the zooming again and I will let you know if it worked or if I need anything else.

Thank you again

Sincerely,

Pantelitsa Mavrovounioti

On 9 September 2015 at 21:10, Claudio Benghi notifications@github.com wrote:

Closed #7 https://github.com/xBimTeam/XbimWindowsUI/issues/7.

— Reply to this email directly or view it on GitHub https://github.com/xBimTeam/XbimWindowsUI/issues/7#event-405122941.