tmpvar / livecad

live coding of 3d surfaces and objects
livecad.wtf
53 stars 2 forks source link

pack AABB with vertex data and fit scene into view #34

Closed tmpvar closed 9 years ago

tmpvar commented 9 years ago

just needs another float buffer from net-oce whilst generating positions/normals and some changes here to automatically move the camera if the object is out of view

tmpvar commented 9 years ago

data being packed in solids/net-oce@fcf8b68bfa8a4cc16ca6128c7cf20349a3f0a0b6 and processed in solids/net-oce-protocol@916e191b20c862b804767835c9ceb66315846f68

Currently it's just comes out as 2 verts packed into a Float64Array which represent the lower/upper extents of the box AABB

tmpvar commented 9 years ago

something like this would work, just need the integration work done

AxisAlignedBox bbox = // Get the bouding box of the thing you want to look at

Vector3 offset = bbox.Maximum - bbox.Center; // Radius of bounding sphere
Vector3 center = bbox.Center;

viewcam.Position = center;
float oneOverSine = 1.0f / (float)System.Math.Sin(viewcam.FOVy.ValueRadians / 2.0); // 1 / sin = adjacent / opposite
float distanceToCenter = offset.Length * oneOverSine; // (adjacent / opposite) * opposite = adjacent
viewcam.Position += (new Vector3(1, 1, 1).NormalisedCopy * distanceToCenter);
viewcam.LookAt(center);

taken from http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=9926

tmpvar commented 9 years ago

functional in 295285fb17158d8285ed1cb34d429d5dac65141c