question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Camera restriction – suggesting changes in code

See original GitHub issue

I think camera restriction is not available currently.

I checked the code and made the changes locally. Can someone please implement the same in the repository?

Need Restrict the camera rotation. Example: while viewing a car model, don’t allow mouse rotation to go down.

Changes Create 6 new dependency properties X range – MinX & MaxX Y range – MinY & MaxY Z range – MinZ & MaxZ

File: HelixToolkit.Wpf.SharpDX\Controls\Viewport3DX.cs Function: ViewCubeClicked()

            if (newPosition.X >= MinX && newPosition.X <= MaxX && ……..)
            {
                pc.AnimateTo(newPosition, e.LookDirection, e.UpDirection, 500);
            }

Function: SetView() Same if() before AnimateTo()

File: HelixToolkit.Wpf.SharpDX\Controls\MouseHandlers\RotateHandler.cs Function: RotateTrackball()

            if (newPosition.X >= MinX && newPosition.X <= MaxX && ……..)
            {
                this.Camera.LookDirection = newTarget - newPosition;
                if (this.CameraMode == CameraMode.Inspect)
                {
                    this.Camera.Position = newPosition;
                }

                this.Camera.UpDirection = newUpDirection;
            }

The same change should be applied in all camera rotation mode.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mk48commented, Apr 10, 2017

I created a custom camera, but still not helping.

when i simply rotate, the object goes down (target is getting changed) see the below screen.

rotate

Below is my code. Could you please copy paste the same in a new project and try to figure it…?!

MainWindow.Xaml

<Window x:Class="HelixCameraControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:HelixCameraControl"
        mc:Ignorable="d"
        xmlns:HX="clr-namespace:HelixToolkit.Wpf.SharpDX;assembly=HelixToolkit.Wpf.SharpDX"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <HX:Viewport3DX Name="viewPort3Dx"
                        CameraRotationMode="Trackball"  
                        RenderTechnique="{Binding RenderTechnique}"
                        ZoomDistanceLimitFar="200"
                        Camera="{Binding MyCamera}"
                        ShowCameraInfo="True"
                        >
            
            <HX:AmbientLight3D Color="1,1,1,1"/>
            <HX:DirectionalLight3D Direction="2,2,10" />
            <HX:DirectionalLight3D Direction="-2,-1,1" />
            
            <HX:MeshGeometryModel3D Geometry="{Binding MGeometryModel}" 
                                    Transform="{Binding MTransform}" 
                                    Material="{Binding MMaterial}"/>
        </HX:Viewport3DX>
    </Grid>
</Window>

MainViewModel.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HelixToolkit.Wpf.SharpDX;
using Media3D = System.Windows.Media.Media3D;

namespace HelixCameraControl
{
    class MainViewModel : Notify
    {
        private RenderTechnique renderTechnique;

        private MeshGeometry3D mGeometryModel;
        private Media3D.Transform3D mTransform;
        private PhongMaterial mMaterial;

        public MainViewModel()
        {
            //// ----------------------------------------------------- Render techniques -----------------------------------------------------
            this.RenderTechniquesManager = new DefaultRenderTechniquesManager();
            this.RenderTechnique = this.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];

            this.MyCamera = new MyRestrictedCamera();

            //------------- Box
            var mb = new MeshBuilder();
            mb.AddBox(new SharpDX.Vector3(0, 0, 0), 5, 5, 5);
            this.MGeometryModel = mb.ToMeshGeometry3D();
            this.MMaterial = new PhongMaterial
            {
                DiffuseColor = SharpDX.Color.Yellow,
                AmbientColor = SharpDX.Color.Black,
                ReflectiveColor = SharpDX.Color.Yellow
            };
            this.MTransform = new Media3D.TranslateTransform3D(0, 0, 0);
        }

        public IRenderTechniquesManager RenderTechniquesManager { get; protected set; }

        public RenderTechnique RenderTechnique
        {
            get
            {
                return this.renderTechnique;
            }

            set
            {
                this.renderTechnique = value;
                this.OnPropertyChanged(nameof(this.RenderTechnique));
            }
        }

        public MyRestrictedCamera MyCamera { get; set; }


        public MeshGeometry3D MGeometryModel
        {
            get
            {
                return this.mGeometryModel;
            }

            set
            {
                this.mGeometryModel = value;
                this.OnPropertyChanged(nameof(this.MGeometryModel));
            }
        }

        public Media3D.Transform3D MTransform
        {
            get
            {
                return this.mTransform;
            }

            set
            {
                this.mTransform = value;
                this.OnPropertyChanged(nameof(this.MTransform));
            }
        }

        public PhongMaterial MMaterial
        {
            get
            {
                return this.mMaterial;
            }

            set
            {
                this.mMaterial = value;
                this.OnPropertyChanged(nameof(this.MMaterial));
            }
        }
    }
}

MyRestrictedCamera.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Media3D;

namespace HelixCameraControl
{
    public class MyRestrictedCamera : HelixToolkit.Wpf.SharpDX.PerspectiveCamera
    {
        private Vector3D up;
        private Vector3D look;

        public override Point3D Position
        {
            get
            {
                return base.Position;
            }

            set
            {
                if (value.Z >= 0)
                {
                    base.Position = value;
                }
            }
        }
        public override Vector3D LookDirection
        {
            get
            {
                return base.LookDirection;
            }

            set
            {
                if (base.Position.Z >= 0)
                {
                    this.look = value;
                    base.LookDirection = value;
                }
                else
                {
                    base.LookDirection = this.look;
                }
            }
        }

        public override Vector3D UpDirection
        {
            get
            {
                return base.UpDirection;
            }

            set
            {
                if (base.Position.Z >= 0)
                {
                    this.up = value;
                    base.UpDirection = value;
                }
                else
                {
                    base.UpDirection = this.up;
                }
            }
        }
    }
}

Notify.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelixCameraControl
{
    public class Notify : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string info)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
        }
    }
}

1reaction
holancecommented, Apr 4, 2017

Seems like what you need is to restrict camera position

Read more comments on GitHub >

github_iconTop Results From Across the Web

Control the camera
Directly controlling a device camera requires a lot more code than requesting pictures or videos from existing camera applications.
Read more >
Camera API
This package is the primary API for controlling device cameras. It can be used to take pictures or videos when you are building...
Read more >
java.lang.IllegalArgumentException: Suggested resolution ...
CameraActivity}: java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1 at android.app.ActivityThread.
Read more >
BG-FGS-start while-in-use permission restriction improvement.
This CL will add further restriction on that. 1. If the first Service.startForeground() call is more than 10 seconds (can be configured by ......
Read more >
clarify source of camera blobs (295670) · Gerrit Code Review
Gerrit Code Review.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found