# How-To Compute a default cameras for a CAD Model

**URL:** <https://forum.techsoft3d.com/t/how-to-compute-a-default-cameras-for-a-cad-model/1354>\
**Category:** HOOPS Exchange\
**Tags:** code, learn, knowledge-base, how-to, 3d-pdf\
**Created:** [November 2, 2021, 4:00am UTC](https://forum.techsoft3d.com/t/how-to-compute-a-default-cameras-for-a-cad-model/1354 "2021-11-02T04:00:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel.peragine](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/gabriel.peragine/32/1535_2.png) [@gabriel.peragine](https://forum.techsoft3d.com/u/gabriel.peragine)\
**Post date:** [November 2, 2021, 4:00am UTC](https://forum.techsoft3d.com/t/how-to-compute-a-default-cameras-for-a-cad-model/1354/1 "2021-11-02T04:00:00Z")

</div>

To programmatically create a “Fit visible” camera, you will compute its value using the model bounding box. In this sample code below you can see a simple way to compute a fit world view

## “Default” camera

1. `A3DMiscComputeBoundingBox` will compute a Bounding Box for the model.
2. Then we compute the center of the bounding box. It will be the camera center.
3. Finally we make a position for the camera. Here I computed a vector from the center position, but you may adjust the values to find the best fitting for your usage.
4. We use the camera in the HOOPS Publish sample UserDefinedViews.

```auto
A3DBoundingBoxData pboxdata;	
A3D_INITIALIZE_DATA(A3DBoundingBoxData, pboxdata);
A3DMiscComputeBoundingBox(pModelFile, 0, &pboxdata);
	
double centerx, centery, centerz;
centerx = pboxdata.m_sMax.m_dX - pboxdata.m_sMin.m_dX;
centery = pboxdata.m_sMax.m_dY - pboxdata.m_sMin.m_dY;
centerz = pboxdata.m_sMax.m_dZ - pboxdata.m_sMin.m_dZ;

double positionx, positiony, positionz;
positionx = centerx + 0.5 * centerx;
positiony = centery + 0.5 * centery;
positionz = centerz + 0.5 * centerz;

// Default view: no button for this default view
CHECK_RET(CreateView(pDoc, p3DArtwork,
	positionx, positiony,positionz,	// camera position
	centerx, centery, centerz, // target position
	0,0,0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	true, viewnameDef, &pViewDef));

```
