Пример #1
0
void Camera::setSize(const int& screenWidth, const int& screenHeight) {
    if (m_type == Camera::Orthographic) {
		// TODO Verify that this works
		setFrustum(-float(screenWidth) / 2.0f, float(screenWidth) / 2.0f, -float(screenHeight) / 2.0f, float(screenHeight) / 2.0f, m_frontMin, m_frontMax);
    } else if (m_type == Camera::Perspective) {
		setFrustum(m_upFovDegrees, float(screenWidth) / float(screenHeight), m_frontMin, m_frontMax);
	}
}
Пример #2
0
void SpatialCamera::setSize(const int& screenWidth, const int& screenHeight) {
	if (m_projectionType == Orthographic) {
		float s = m_projectionParameters.t - m_projectionParameters.b;
		float l = float(screenWidth) / float(screenHeight) / -2.0f * s;
		float r = -l;
		float b = -0.5f * s;
		float t = -b;
		setFrustum(l, r, b, t, m_projectionParameters.n, m_projectionParameters.f);
	} else if (m_projectionType == Perspective) {
		setFrustum(m_upFovRadian, float(screenWidth) / float(screenHeight), m_projectionParameters.n, m_projectionParameters.f);
	}
}
Пример #3
0
void ProxyViz::updateViewFrustum(const MDagPath & cameraPath)
{
	MMatrix cameraMat = cameraPath.inclusiveMatrix();
	AHelper::ConvertToMatrix44F(*cameraSpaceR(), cameraMat);
	MMatrix cameraInvMat = cameraPath.inclusiveMatrixInverse();
	AHelper::ConvertToMatrix44F(*cameraInvSpaceR(), cameraInvMat);
	float peye[3];
	peye[0] = cameraMat.matrix[3][0];
	peye[1] = cameraMat.matrix[3][1];
	peye[2] = cameraMat.matrix[3][2];
	setEyePosition(peye);
	
    float farClip = -20.f;
    if(numPlants() > 0) getFarClipDepth(farClip, gridBoundingBox() );
    
	MFnCamera fcam(cameraPath.node() );
	if(fcam.isOrtho() ) {
		float orthoW = fcam.orthoWidth();
		float orthoH = orthoW * fcam.aspectRatio();
		setOrthoFrustum(orthoW, orthoH, -10.f, farClip );
		
	} else {
		float hfa = fcam.horizontalFilmAperture();
		float vfa = fcam.verticalFilmAperture();
		float fl = fcam.focalLength();
	
		setFrustum(hfa, vfa, fl, -10.f, farClip );
	}
	setOverscan(fcam.overscan() );
}
Пример #4
0
void onDraw()
{
  /*setViewer O(1)*/
  setMatrixMode(PROJECTION);
  initMatrix();
  setViewer(vertex(eyex, eyey, eyez), vertex(lookx, looky, lookz), vertex(upx, upy, upz));
  setFrustum(10, 10*MAX_H/MAX_W, 4, 25);

  /*createPolygons O(1)*/
  initScene();
  setMatrixMode(MODELVIEW); 
  initMatrix();
  blockWithHole(-5.0,0.0,0.0);
  blockColoured(barx, bary, 0.0);

 
  /*calcData*/
  /*
    For each polygon,
      Go to next triangle if current polygon doesn't face viewer O(1)
      Calculate pixel values of vertices of the triangle O(1)
      clip triangle  //unless you model your scene such that no part ever goes outside the viewport (commentception) O(1)
      For each triangle, O(m*n)
        Add x,y,z position of scan conversion pixels to temp per-polygon table (indexed on y position with min and max x values)
        Also store a min and max x for y=0, y=MAX_Y-1. Add the x,y values for the points in between to the temp table
        Copy temp table to data table with the points between min and max x values filled (in case of conlict, min z value only) O(m*n)
  */

  /*drawPixels*/
  if(q4) innerclipTriangles();
  renderScene();
  glDrawPixels(MAX_W, MAX_H, GL_RGBA, GL_BYTE, data);
  glFlush();
}
Пример #5
0
void ProxyViz::updateViewFrustum(MObject & thisNode)
{
	MPlug matplg(thisNode, acameraspace);
	MObject matobj;
	matplg.getValue(matobj);
	MFnMatrixData matdata(matobj);
    MMatrix cameramat = matdata.matrix(); 
	AHelper::ConvertToMatrix44F(*cameraSpaceR(), cameramat);
	AHelper::ConvertToMatrix44F(*cameraInvSpaceR(), cameramat.inverse() );
	float peye[3];
	peye[0] = cameramat.matrix[3][0];
	peye[1] = cameramat.matrix[3][1];
	peye[2] = cameramat.matrix[3][2];
	setEyePosition(peye);
	
	MPlug hfaplg(thisNode, ahapeture);
	float hfa = hfaplg.asFloat();
	MPlug vfaplg(thisNode, avapeture);
	float vfa = vfaplg.asFloat();
	MPlug flplg(thisNode, afocallength);
	float fl = flplg.asFloat();
	
    float farClip = -20.f;
    if(numPlants() > 0) getFarClipDepth(farClip, gridBoundingBox() );
    
    setFrustum(hfa, vfa, fl, -10.f, farClip );
	
	MPlug overscanPlug(thisNode, ainoverscan);
	setOverscan(overscanPlug.asDouble() );
}
Пример #6
0
///////////////////////////////////////////////////////////////////////////////
// set a symmetric perspective frustum with 4 params similar to gluPerspective
// (vertical field of view, aspect ratio, near, far)
///////////////////////////////////////////////////////////////////////////////
void ModelGL::setFrustum(float fovY, float aspectRatio, float front, float back)
{
    float tangent = tanf(fovY/2 * DEG2RAD);   // tangent of half fovY
    float height = front * tangent;           // half height of near plane
    float width = height * aspectRatio;       // half width of near plane

    // params: left, right, bottom, top, near, far
    setFrustum(-width, width, -height, height, front, back);
}
Пример #7
0
//-----------------------------------------------------------------------------BBOX
// setup bouding box
void Camera::bbox(float3 mn_, float3 mx_, bool review){
	mn = mn_ ;	mx=mx_ ;
	setado = true;
	
	bs.c = (mn+mx)/2;
	bs.r = (bs.c-mn).length();
	
	setFrustum();
	
	if( review ) perspective();
}
Пример #8
0
void OpenGLRenderer::setPerspective(float fovy, float aspect, float zNear, float zFar)
{
	float xmin, xmax, ymin, ymax;

	ymax = zNear * Math::tan(fovy * Math::PI / 360.0f);
	ymin = -ymax;
	xmin = ymin * aspect;
	xmax = ymax * aspect;

	setFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
Пример #9
0
BaseView::BaseView() 
{
	m_centerOfInterest.set(0.f, 0.f, 0.f);
	m_space.setIdentity();
	m_space.setTranslation(Vector3F(0.f, 0.f, 100.f) );
	m_invSpace.setIdentity();
	m_invSpace.setTranslation(Vector3F(0.f, 0.f, -100.f) );
	
/// 35mm Academy
	std::cout<<"\n angle of view "<<180.f/3.14f*2.f * atan(21.9456f/2.f/35.f)<<" deg";
	setFrustum(.864f, .63f, 35.f, -1.f, -20000.f);
	
}
Пример #10
0
void BaseView::frameAll(const BoundingBox & b)
{
	Vector3F eye = b.center();
	eye.z = b.getMax(2) + b.distance(0) / hfov() * .55f + 120.f;
	setEyePosition(eye);
	
	Matrix44F m;
	m.setTranslation(eye);
	*cameraSpaceR() = m;
	m.inverse();
	*cameraInvSpaceR() = m;
	setFrustum(1.33f, 1.f, 26.2f, -1.f, -1000.f);
}
Пример #11
0
///////////////////////////////////////////////////////////////////////////////
// configure projection and viewport
///////////////////////////////////////////////////////////////////////////////
void ModelGL::setViewport(int x, int y, int w, int h)
{
    // set viewport to be the entire window
    glViewport((GLsizei)x, (GLsizei)y, (GLsizei)w, (GLsizei)h);

    // set perspective viewing frustum
    setFrustum(FOV_Y, (float)(w)/h, NEAR_PLANE, FAR_PLANE); // FOV, AspectRatio, NearClip, FarClip

    // copy projection matrix to OpenGL
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf(matrixProjection.getTranspose());
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
Пример #12
0
void CC3Camera::populateFrom( CC3Camera* another )
{
    super::populateFrom( another );

    setFrustum( (CC3Frustum*)another->_frustum->copy()->autorelease() ) ;

    _fieldOfView = another->getFieldOfView();
    _fieldOfViewOrientation = another->getFieldOfViewOrientation();
    _fieldOfViewAspectOrientation = another->getFieldOfViewAspectOrientation();
    _nearClippingDistance = another->getNearClippingDistance();
    _farClippingDistance = another->getFarClippingDistance();
    _isProjectionDirty = another->_isProjectionDirty;
    _isOpen = another->isOpen();
}
Пример #13
0
void TV3DManager::configureCamera(Camera& whichCamera, int screenWidth, int screenHeight) {
    if (screenHeight == 0) {
        screenHeight = 1; // prevent divide by 0
    }
    _screenWidth = screenWidth;
    _screenHeight = screenHeight;
    _aspect= (double)_screenWidth / (double)_screenHeight;
    setFrustum(whichCamera);

    glViewport (0, 0, _screenWidth, _screenHeight); // sets drawing viewport
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
Пример #14
0
///////////////////////////////////////////////////////////////////////////////
// configure projection and viewport of sub window
///////////////////////////////////////////////////////////////////////////////
void ModelGL::setViewportSub(int x, int y, int width, int height, float nearPlane, float farPlane)
{
    // set viewport
    glViewport(x, y, width, height);
    glScissor(x, y, width, height);

    // set perspective viewing frustum
    setFrustum(FOV_Y, (float)(width)/height, nearPlane, farPlane); // FOV, AspectRatio, NearClip, FarClip

    // copy projection matrix to OpenGL
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf(matrixProjection.getTranspose());
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
Пример #15
0
void CC3Camera::initWithTag( GLuint aTag, const std::string& aName )
{
    super::initWithTag( aTag, aName );
    {
        setFrustum( CC3Frustum::frustum() );		// use setter for backpointer
        _isProjectionDirty = true;
        _fieldOfView = kCC3DefaultFieldOfView;
        _fieldOfViewOrientation = CC3FieldOfViewOrientationDiagonal;
        _fieldOfViewAspectOrientation = CC3UIInterfaceOrientationLandscapeLeft;
        _nearClippingDistance = kCC3DefaultNearClippingDistance;
        _farClippingDistance = kCC3DefaultFarClippingDistance;
        _viewport = CC3ViewportMake(0, 0, 0, 0);
        _shouldClipToViewport = false;
        _hasInfiniteDepthOfField = false;
        _isOpen = false;
    }
}
Пример #16
0
void onDraw()
{
  /*setViewer O(1)*/
  setMatrixMode(PROJECTION);
  initMatrix();
  setViewer(vertex(eyex, eyey, eyez), vertex(lookx, looky, lookz), vertex(upx, upy, upz));
  setFrustum(10, 10*MAX_H/MAX_W, 4, 25);

  /*createPolygons O(1)*/
  initScene();
  setMatrixMode(MODELVIEW); 
  initMatrix();
  if(!Aisclippingwindow)
	drawA(Ax, Ay, Az);
  drawB(Bx, By, Bz);

  /*drawPixels*/
  renderScene();
  glDrawPixels(MAX_W, MAX_H, GL_RGBA, GL_BYTE, data);
  glFlush();
}
Пример #17
0
void BaseView::updateFrustum()
{ setFrustum(.864f, .63f, 35.f, -1.f, m_farClip); }
Пример #18
0
Camera::Camera( float w, float h, float near, float far ) {
    ASSERT_ALIGNED(this);
    setFrustum(w, h, near, far);
}
Пример #19
0
KFrustum::KFrustum(const KMatrix4x4 &viewProj)
{
  setFrustum(viewProj);
}
Пример #20
0
toxi::geom::Matrix4x4 toxi::geom::Matrix4x4::setPerspective( const double & fov, const double & aspect, const double & near, const double & far )
{
	double y = near * std::tan(0.5 * toxi::math::MathUtils::radians(fov));
	double x = aspect * y;
	return setFrustum(-x, x, y, -y, near, far);
}