Class ViewParams

3DS Max Plug-In SDK

Class ViewParams

See Also: Class Matrix3, Class Renderer, Class RendParams.

class ViewParams : public BaseInterfaceServer

Description:

This class describes the properties of a view that is being rendered. These are properties such as the type of view (parallel or perspective), its clipping distances, width, height, zoom factor, field-of-view, etc.

Data Members:

public:

Matrix3 prevAffineTM;

This is the world space to camera space transformation matrix computed 2 ticks before the affineTM matrix below.

Matrix3 affineTM;

This matrix will take a point in world space and convert it to camera space (or world to view space if it's a viewport). The camera coordinates are set up looking down the -Z axis, X is to the right, and Y is up.

int projType;

One of the following values:

PROJ_PERSPECTIVE

The view is a perspective projection.

PROJ_PARALLEL

The view is a parallel projection.

float hither, yon;

The hither and yon clipping distances.

float distance;

This data member is available in release 3.0 and later only.

The distance from the view point to the image (view) plane.

float zoom;

The zoom factor of the viewport for parallel projection. The zoom factor gives the amount of magnification relative to a standard view width of 400 pixels. This is best explained via the following code fragment: ComputeViewParams() computes the projection factors for a given view, and MapToScreen() applies these factors to map a point from 3D camera coordinates to 2D screen coordinates.

#define VIEW_DEFAULT_WIDTH ((float)400.0)

void SRendParams::ComputeViewParams(const ViewParams&vp) {

 if (vp.projType == PROJ_PERSPECTIVE) {

  float fac = -(float)(1.0 / tan(0.5*(double)vp.fov));

  xscale = fac*dw2; // dw2 = float(devWidth)/2.0

  yscale = -devAspect*xscale;

  }

 else {

  xscale = (float)devWidth/(VIEW_DEFAULT_WIDTH*vp.zoom);

  yscale = -devAspect*xscale;

  }

 }

Point2 SRendParams::MapToScreen(Point3 p) {

 Point2 s;

 if (proj_type==PROJ_PERSPECTIVE) {

  s.x = dw2 + xscale*p.x/p.z;

  s.y = dh2 + yscale*p.y/p.z;

  }

 else {

  s.x = dw2 + xscale*p.x;

  s.y = dh2 + yscale*p.y;

  }

 return s;

 }

float fov;

Field of view in radians for perspective projections.

float nearRange;

This data member is available in release 2.0 and later only.

The near environment range setting (used for fog effects).

float farRange;

This data member is available in release 2.0 and later only.

The far environment setting (used for fog effects).

Methods:

Prototype:

virtual INT_PTR Execute(int cmd, ULONG arg1=0, ULONG arg2=0, ULONG arg3=0);

Remarks:

This method is available in release 2.0 and later only.

This is a general purpose function that allows the API to be extended in the future. The 3ds max development team can assign new cmd numbers and continue to add functionality to this class without having to 'break' the API.

Parameters:

int cmd

The index of the command to execute.

ULONG arg1=0

Optional argument 1. See the documentation where the cmd option is discussed for more details on these parameters.

ULONG arg2=0

Optional argument 2.

ULONG arg3=0

Optional argument 3.

Return Value:

An integer return value. See the documentation where the cmd option is discussed for more details on the meaning of this value.