View/Camera Wrapper

Hi all,

Being bored and having a cold I put together a little wrapper for SketchUp’s view and camera. This module has methods for getting and setting perspective field of view as well as parallel projection width and height, both including and excluding the safe frame bars. It can also be used to set the aspect ratio without visually changing the projection.

Hope someone finds it useful!

3 Likes

Now updated with methods for getting frustrum planes, both including and excluding the gray safe frame bars.

I always booboo the spelling myself …

https://en.wiktionary.org/wiki/frustrum
1. Misspelling of frustum .

Denis was asking for 3D points of the corners of what (I think) are the near frustum plane ?
(… or did he want the corners of where the view frustum crosses the image plane ?)

These things and perhaps near and far clipping planes might be beneficial.


When writing library modules, wouldn’t it be better to define them as instance methods and put a call to
module_function at the top, so as to allow use either with qualified library method calls or mixing into modules and classes via include ?

if you want a real challenge…

include 2 Point Perspective…

it is so hard to manipulate with code because half it’s functions are buried in the ‘Tool’…

john

Spelling fixed.

I prefer to keep it simple and explicitly call library methods on the library module to easily see where they are coming from.

Regarding 2 point perspective I don’t think it is exposed in the API, other than 3 getters for the panning, zooming and wether it is being used.

The library now has zoom to/zoom extents functionality, with custom padding.

In parallel projection it is identical to SU’s own Zoom Extents, down to the very last decimal. In perspective I frankly don’t understand what SketchUp is doing and couldn’t recreate it, but I think my algorithm, lowering the angles on a copy of the frustum and then adjust it to contain the point, produces a better results with the same padding on all sides of the view.


Native parallel projection Zoom Extents


Parallel projection zoom extents with library (identical)


Native perspective Zoom Extents (feet on padding!)


Perspective Zoom Extents with library (contained within padding :slight_smile: )