View Blog

Technical discussions
Post Reply
nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

View Blog

Post by nickz »

In this thread I would like to expand more informally concepts related to interactive view manipulation and its programming. See also http://www.dynoinsight.com/Help/Geom/View/Scene3D.aspx

The best way to understand it is probably to open any sample (View Point or Zoom are good to see the programmatic manipulation) and play with the Birds Eye view (http://www.dynoinsight.com/phpBB3/viewt ... f=2&t=2970) a little while reading. In case you are using version earlier than 5.0 you can have it installed simultaneously. Just do not forget to activate the one you need via “Update Component Registration”

The core concept of View Volume is simple. You need to define which part of the world is displayed on the screen. It is determined by the View Volume which is simply an arbitrary oriented 3D box in space

Whatever is inside the box is projected to the front side of the box (or another plane in front, which does not matter), converted to pixels and this is what you get in the KC window

The view manipulations either interactively with mouse or in code are simply manipulations of position, orientation and size of the box. Zoom in, for example, is reduction of size of the view volume without changing anything else

For case of perspective projection the difference is minor in my view: Instead of a box you get a frustum, which is a slightly distorted box, but later about that

More to follow...

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

View Volume

Post by nickz »

As with all oriented objects in KC View Volume (sometimes also called Clip Volume or Clip Box) is defined by a frame (axes of coordinates), called Eye Frame and three ranges along each axis of the frame

Z axis of the Eye Frame is directed towards the viewer (see the birds eye view) perpendicular to the imaginable plane of the screen. Unlike the name suggest Its origin is normally located inside the Viewing Volume

On the start when no default view point is defined origin of the Eye Frame is located at the global origin. More precisely Eye Frame is a copy of the global frame, which is rotated by 10 degrees around x and by 10 degrees around y axes

After various view manipulations location and ranges defining the View Volume can be anything. So the Eye frame does not have to be cantered or be symmetrical WRT the View Volume box

Any view manipulation is reduced to moving the Eye Frame around and changing ranges of the clop box. Lengths of X and Y ranges are restricted by one equation: Length of y range / Length of X range is always equal to aspect ratio of the KernelCAD's window. Otherwise there would be a distortion

For completeness: Many game engines have very close notion of a camera. There is no such object in version 4.4 or earlier. In v5.0 a camera object is defined internally, but it is not exposed via interface (yet), as it is an equivalent notion. A camera object is a View Volume with restrictions that z range lies strictly in negative half and x and y range are symmetrical WRT zero. This is a simple transformation

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Programmatic View Manupulation

Post by nickz »

All viewing interfaces http://www.dynoinsight.com/Help/Interfa ... faces.aspx result in (and only) manipulation of View Volume. They are the various ways which can be convenient in different situations

To manipulate the View Volume directly you need to access the Eye Frame via: KernelCAD > GetView() > IPropertyArray > GetProperty("EyeFrame",..) > IFrame and modify position and orientation of the frame. Query other IFrame* ot I3DObject from the IFrame to get more functionality to modify the frame

Ranges (size) of the view volume can be mofified via ILook: http://www.dynoinsight.com/Help/ILook.aspx It needs some care as the aspect ratio of the x and y dimensions must be constant (see above). The interface does not restrict it automatically. So the right way is to calculate the current ratio as height/width and make sure new size has same ratio

Reducing the z range can clip out some objects which can be confusing. Sometimes it is desirable. This is what depth zoom does. I will write a bit about it. Increasing it too much can make view rotations with the mouse too fast. The preferred z range should be symmetric, about 2 times larger than the largest dimension of the whole model to avoid clipping on rotations

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Z range, rotation center and depth zoom

Post by nickz »

Z range (depth range) is the range of the View Volume along z axis of the eye frame. It determines the near and far clipping planes. It is important because objects outside can be clipped away. This happens for example when you create an object programmatically which is not completely inside the range. It can be very confusing when the object is clipped out completely. You just do not see an object which should be in the scene. Open Model Explorer, select the object of interest and press "Go To" in the case

KC has a way to modify the z range interactively. It is called depth zoom. To see how it works open any sample and hold z key. The range will be displayed with two horizontal lines. If you do not see the lines zoom out a little first. To reduce the range click into the window and select a vertical range with a mouse stroke

The scene displayed in the depth zoom mode is the view from the bottom. It is as if you were looking at a car and then slid under it legs first

One advantage of the depth zoom is that when you have a clattered scene (a dense wireframe display for example) you can focus on objects behind or in a certain range and clip out the rest from the view temporary

Interactive rotations of the scene with the mouse are performed around the centre of the View Volume. Keep it in mind during 3D navigation. One common 3D navigation issue is that when the depth range is too large and an object of interest is far from its centre the object can jump around wildly during small rotations. The first thing to do in the situation is to reduce depth zoom and make it centred around the object

More about 3D navigation shortly...

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

3D Navigation

Post by nickz »

Very common problem confronting newbies in 3D is an empty screen :) or some objects are missing. Most often this is because they fall out of the View Volume completely. The first thing to check in the situation is to open the Model Explorer and check if the object(s) is there. Toggle visibility (works with multi selection too) to see how names are mapped to 3D. When you found your object select it and press "Go To". The view will be focused on it. Zooming out slowly will identify the location. This is also a good option when you are lost in 3D

Another option which should help is Advanced > View >Fit option in the context menu. Another quick thing is to check the depth range by pressing z (see the previous post)

Apart from the standard ways to manipulate the View Volume with the mouse or programmatically mentioned above there are also view points. See the Point Of View sample. The default view point, if created, defines a custom initial configuration of View Volume displayed on start of the application. Point Of View sample can be used as an editor to add view points. There are Open and Save menu options. Nothing to program. To make the view point more accurate it is better record the view point in a window which has the same aspect ration as the target application

You could have few predefined view points in your app and allow the user to activate them with a GUI click. IViewPoint.SetCurrent2() creates animated smooth transition from one point to another http://www.dynoinsight.com/Help/Interfa ... etCurrent2. For an array of view points this can provide a kind of walking around a path and/or looking around and zooming functionality. See more at http://www.dynoinsight.com/Help/Geom/Vi ... oints.aspx

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Orthographic vs Perspective

Post by nickz »

The above is true for most graphic software. It is definitely true for the low level DirectX and Open GL libraries on which probably 99% of the 3D software is built. The difference matters only for software developers and only when they need some advanced view manipulation. As I mentioned already the difference is mostly related where the local frame (Eye Frame in KC case) to which the View Volume is tied is located

For completeness I will mention quickly projection types. In very brief terms the 3D scene is projected to a 2D rectangle, pixelated and this is what you get in 3D window. There are two ways to do the projection, namely Orthographic and Perspective. Orthographic is the simpler one with parallel lines. Perspective projection uses rays coming out of single point (center of the projection). In this case software uses Frustum https://en.wikipedia.org/wiki/Viewing_frustum for Viewing Volume instead of a box. There are some differences in handling, but mostly nearly all concepts and methods of handling Viewing Volume apply to frustums without much change

Perspective projection is more realistic. Its main feature is that the far objects appear smaller in pixels. It is important for sparse, outdoor kind of scenes. Orthographic projecting is more used and often more appropriate for engineering applications where exact 2D projections are important

At the moment KC supports only orthographic projection. One reason for that in v4.* was that the important Open Cascade component does not have it. We were keen to add it in v5.0, but unfortunately we have to push it back to v5.1. There will be a way to switch it at runtime

Post Reply