void DiscreteDepthDistortionModel::undistort(cv::Mat & depth) const
  {
    UASSERT(width_ == depth.cols);
    UASSERT(height_ ==depth.rows);
    UASSERT(depth.type() == CV_16UC1 || depth.type() == CV_32FC1);
    if(depth.type() == CV_32FC1)
    {
		#pragma omp parallel for
		for(int v = 0; v < height_; ++v) {
		  for(int u = 0; u < width_; ++u) {
			 float & z = depth.at<float>(v, u);
			if(uIsNan(z) || z == 0.0f)
			  continue;
			double zf = z;
			frustum(v, u).interpolatedUndistort(&zf);
			z = zf;
		  }
		}
    }
    else
    {
		#pragma omp parallel for
		for(int v = 0; v < height_; ++v) {
		  for(int u = 0; u < width_; ++u) {
		    unsigned short & z = depth.at<unsigned short>(v, u);
			if(uIsNan(z) || z == 0)
			  continue;
			double zf = z * 0.001;
			frustum(v, u).interpolatedUndistort(&zf);
			z = zf*1000;
		  }
		}
    }
  }
Example #2
0
Mat4 perspective(const float fovy, const float ar, const float n, const float f) {
	float t = n * tan(M_PI * fovy / 360);
	float b = -t;
	float r = t * ar;
	float l = -r;
	return frustum(l, r, t, b, n, f);
}
Example #3
0
void Camera::perspective(float fovy, float aspect, float zNear, float zFar) {
    float top    =  tan(fovy/2.0f) * zNear;
    float bottom =  -top;
    float left   = aspect * bottom;
    float right  = aspect * top;
    frustum(left, right, bottom, top, zNear, zFar);
}
Example #4
0
void init(void)
{
    // GL inits
    glClearColor(0.2,0.2,0.5,0);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    printError("GL inits");

    projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 50.0);

    // Load and compile shader
    program = loadShaders("shaders/terrain.vert", "shaders/terrain.frag");
    glUseProgram(program);
    printError("init shader");

    glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
    glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0
    LoadTGATextureSimple("maskros512.tga", &tex1);

// Load terrain data

    LoadTGATextureData("fft-terrain.tga", &ttex);
    tm = GenerateTerrain(&ttex);
    printError("init terrain");
}
  size_t DiscreteDepthDistortionModel::accumulate(const cv::Mat& ground_truth,
                                                  const cv::Mat& measurement)
  {
    UASSERT(width_ == ground_truth.cols);
    UASSERT(height_ == ground_truth.rows);
    UASSERT(width_ == measurement.cols);
    UASSERT(height_ == measurement.rows);
    UASSERT(ground_truth.type() == CV_16UC1 || ground_truth.type() == CV_32FC1);
    UASSERT(measurement.type() == CV_16UC1 || measurement.type() == CV_32FC1);

    bool isGroundTruthInMM = ground_truth.type()==CV_16UC1;
    bool isMeasurementInMM = measurement.type()==CV_16UC1;

    size_t num_training_examples = 0;
    for(int v = 0; v < height_; ++v) {
      for(int u = 0; u < width_; ++u) {
    	  float gt = isGroundTruthInMM?float(ground_truth.at<unsigned short>(v,u))*0.001:ground_truth.at<float>(v,u);
        if(gt == 0)
          continue;
        float meas = isMeasurementInMM?float(measurement.at<unsigned short>(v,u))*0.001:measurement.at<float>(v,u);
        if(meas == 0)
          continue;

        UScopeMutex sm(mutex_);
        frustum(v, u).addExample(gt, meas);
        ++num_training_examples;
      }
    }

    training_samples_ += num_training_examples;

    return num_training_examples;
  }
Example #6
0
//////////////////////////////////////////////////////////////////////////
// perspProjectionVertical
void BcMat4d::perspProjectionVertical( BcReal Fov, BcReal Aspect, BcReal Near, BcReal Far )
{
	const BcReal H = BcTan( Fov ) * Near;
	const BcReal W = H / Aspect;
	
    frustum( -W, W, H, -H, Near, Far );
}
Example #7
0
void init(void)
{	
  dumpInfo();

	// GL inits
	glClearColor(1,1,1,0);;
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_CULL_FACE);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	printError("GL inits");

  // Airplane
  Dynamics_Init(&forward, &up, &right, &position, &velocity);
  Airplane_Init(&thrust, &yawRate, &pitchRate, &rollRate, &firstPersonView, &resetFlag);
  
  // Camera
  Camera_Init(firstPersonView, &forward, &up, &position, velocity, &camera_position, &camera_look, camMatrix);
  
  // Terrain and skybox
  World_Init(&camera_position, &camera_look);

  // Init game
  Game_Init();
	
  // Projection matrix
  frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 200.0, projMatrix);
	
  printError("init arrays");	
}
Example #8
0
    void Camera::perspective (Real left, Real right, Real bottom, Real top, Real n, Real f)
    {

        MvGl2DemoMatrixIdentity(mProjectionMatrix);
        frustum (mProjectionMatrix, left, right, bottom, top, n, f);
        return;
    }
  size_t DiscreteDepthDistortionModel::accumulate(const DepthMat& ground_truth,
                                                  const DepthMat& measurement)
  {
    assert(width_ == ground_truth.cols());
    assert(height_ == ground_truth.rows());
    assert(width_ == measurement.cols());
    assert(height_ == measurement.rows());

    size_t num_training_examples = 0;
    for(int v = 0; v < height_; ++v) {
      for(int u = 0; u < width_; ++u) {
        if(ground_truth.coeffRef(v, u) == 0)
          continue;
        if(measurement.coeffRef(v, u) == 0)
          continue;

        double gt = ground_truth.coeffRef(v, u) * 0.001;
        double meas = measurement.coeffRef(v, u) * 0.001;
        frustum(v, u).addExample(gt, meas);
        ++num_training_examples;
      }
    }

    return num_training_examples;
  }
Example #10
0
void init(void)
{
  forward = SetVector(1,1,1);
  // GL inits
  glClearColor(0.2,0.2,0.5,0);
   glEnable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  glCullFace(GL_BACK);
  printError("GL inits");

  projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 500.0);

  // Load and compile shader
  
  programSky = loadShaders("sky.vert", "sky.frag");
  skybox = LoadModelPlus("skybox.obj");
  program = loadShaders("terrain.vert", "terrain.frag");
  //goal = LoadModelPlus("cube.obj"); // If I put this here the walls get darker
  
  printError("init shader");
	
  
  glUseProgram(programSky);
  glActiveTexture(GL_TEXTURE2);	 
  glUniform1i(glGetUniformLocation(programSky, "tex"),2); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, myTex);
  LoadTGATextureSimple("SkyBox512.tga", &myTex); 

	  glActiveTexture(GL_TEXTURE3);	 
  glUniform1i(glGetUniformLocation(program, "tex"),3); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, tex3);
  LoadTGATextureSimple("gold.tga", &tex3);

  glUseProgram(program);
  glActiveTexture(GL_TEXTURE0);	
  glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
  glUniform1i(glGetUniformLocation(program, "tex"),0); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, tex1);
  LoadTGATextureSimple("maskros512.tga", &tex1);

  glActiveTexture(GL_TEXTURE1);	 
  glUniform1i(glGetUniformLocation(program, "tex"),1); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, tex2);
  LoadTGATextureSimple("dirt.tga", &tex2);
  // Load terrain data
	

  
  LoadTGATextureData("MazeWall.tga", &ttexm);
  LoadTGATextureData("fft-terrain.tga", &ttex);
  tm = GenerateMazeTerrain(&ttexm,&ttex,vertexArray);
  mm = GenerateTerrain(&ttex,vertexArray);
  goal = LoadModelPlus("groundsphere.obj"); // The walls do not get darker
  printError("init terrain");


	sfMakeRasterFont(); // init font
	sfSetRasterSize(600, 200);
}
//------------------------------------------------------------------------------
//
void GLPickingSelect::processTriangles(
    const SubNode::Ptr rootNode,
    const double seconds,
    const size_t numTriangles,
    VBOProxy::VBOMode vboMode
)
{
    const unsigned int bufferSize = (unsigned int)std::min(numTriangles,size_t(100000));
    boost::shared_array<GLuint>buffer (new GLuint[bufferSize*4]);

    M3dView view = fSelectInfo.view();

    MMatrix projMatrix;
    view.projectionMatrix(projMatrix);
    MMatrix modelViewMatrix;
    view.modelViewMatrix(modelViewMatrix);

    unsigned int x, y, w, h;
    view.viewport(x, y, w, h);
    double viewportX = static_cast<int>(x);   // can be less than 0
    double viewportY = static_cast<int>(y);   // can be less than 0
    double viewportW = w;
    double viewportH = h;

    fSelectInfo.selectRect(x, y, w, h);
    double selectX = static_cast<int>(x);  // can be less than 0
    double selectY = static_cast<int>(y);  // can be less than 0
    double selectW = w;
    double selectH = h;

    MMatrix selectAdjustMatrix;
    selectAdjustMatrix[0][0] = viewportW / selectW;
    selectAdjustMatrix[1][1] = viewportH / selectH;
    selectAdjustMatrix[3][0] = ((viewportX + viewportW/2.0) - (selectX + selectW/2.0)) / 
        viewportW * 2.0 * selectAdjustMatrix[0][0];
    selectAdjustMatrix[3][1] = ((viewportY + viewportH/2.0) - (selectY + selectH/2.0)) /
        viewportH * 2.0 * selectAdjustMatrix[1][1];

    MMatrix localToPort = modelViewMatrix * projMatrix * selectAdjustMatrix;

    view.beginSelect(buffer.get(), bufferSize*4);
    view.pushName(0);
    {
        Frustum frustum(localToPort.inverse());
        MMatrix xform(modelViewMatrix);
        
        DrawShadedState state(frustum, seconds, vboMode);
        DrawShadedTraversal traveral(state, xform, false, Frustum::kUnknown);
        rootNode->accept(traveral);
    }
    view.popName();
    int nbPick = view.endSelect();

    if (nbPick > 0) {
        unsigned int Zdepth = closestElem(nbPick, buffer.get());    
        float depth = float(Zdepth)/MAX_HW_DEPTH_VALUE;
        fMinZ = std::min(depth,fMinZ);
    }
}
Example #12
0
Matrix4 perspective(Scalar fovy, Scalar aspectRatio, Scalar near, Scalar far)
{
  Scalar xMax, yMax;
  yMax = near * Tangent(DegToRad(fovy / 2));
  xMax = yMax * aspectRatio;
  return frustum(-xMax, xMax, -yMax, yMax, near, far);

}
Example #13
0
void Matrix::perspective(float fovy, float aspect, float nearZ, float farZ) {
    float frustumW, frustumH;

    frustumH = tanf(fovy / 360.0 * M_2_PI) * nearZ;
    frustumW = frustumH * aspect;

    frustum(-frustumW, frustumW, -frustumH, frustumH, nearZ, farZ);
}
Example #14
0
bool ViewCull::cullByFrustum(const Vector3F & center, const float & radius) const
{
	gjk::Sphere B;
	B.set(center, radius );
	if( gjk::Intersect1<AFrustum, gjk::Sphere>::Evaluate(frustum(), B) )
		return false;
	return true;
}
Example #15
0
void Matrix::prespective(float fovy, float aspect, float nearz, float farz)
{
	float frustumW, frustumH;
	frustumH = tanf(fovy / 360.0f * 3.14159265) * nearz;
	frustumW = frustumH * aspect;

	frustum( -frustumW, frustumW, -frustumH, frustumH, nearz, farz);
}
Example #16
0
 Matrix4d perspective(double fov, double aspect, double z_near, double z_far)
 {
   auto t =  z_near * double(std::tan(fov * M_PI / 360.));
   auto b = -t;
   auto l = aspect * b;
   auto r = aspect * t;
   return frustum(l, r, b, t, z_near, z_far);
 }
TriMatrix TriMatrix::viewToClip()
{
	float near = 5.0f;
	float far = 65536.0f;
	float width = (float)(FocalTangent * near);
	float top = (float)(CenterY / InvZtoScale * near);
	float bottom = (float)(top - viewheight / InvZtoScale * near);
	return frustum(-width, width, bottom, top, near, far);
}
Example #18
0
void render() {

    if (initialized == false) {
        glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
        spherePositionsId = createSpherePositions();
        sphereNormalsId = createSphereNormals(positions);
        createProgram();
        startTimeMillis = currentTimeMillis();
        initialized = true;
    }

    frameCount++;
    totalFrameCount++;
    long now = currentTimeMillis();
    long elapsed = now - startTimeMillis;
    static long lastTimerCall = 0;
    if ((now - lastTimerCall) > 250) {
        timer(0);
        lastTimerCall = now;
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glUseProgram(programId);

    //
    // calculate the ModelViewProjection and ModelViewProjection matrices
    //
    matrix44 tmp, mv, mvp, frustumMat, translateMat, rotateMat1, rotateMat2;
    frustum(frustumMat, left, right, bottom / aspectRatio, top / aspectRatio, nearPlane, farPlane);
    translate(translateMat, 0.0f, 0.0f, -3.0f);
    rotate(rotateMat1, 1.0f * elapsed / 50, 1.0f, 0.0f, 0.0f);
    rotate(rotateMat2, 1.0f * elapsed / 100, 0.0f, 1.0f, 0.0f);
    multm(tmp, rotateMat1, rotateMat2);
    multm(mv, translateMat, tmp);
    multm(mvp, frustumMat, mv);

    // set the uniforms before rendering
    GLuint mvpMatrixUniform = glGetUniformLocation(programId, "mvpMatrix");
    GLuint mvMatrixUniform = glGetUniformLocation(programId, "mvMatrix");
    GLuint colorUniform = glGetUniformLocation(programId, "color");
    GLuint ambientUniform = glGetUniformLocation(programId, "ambient");
    GLuint lightDirUniform = glGetUniformLocation(programId, "lightDir");
    glUniformMatrix4fv(mvpMatrixUniform, 1, false, mvp);
    glUniformMatrix4fv(mvMatrixUniform, 1, false, mv);
    glUniform3f(lightDirUniform, 1.0f, -1.0f, -1.0f);
    glUniform4f(colorUniform, 0.5f, 0.5f, 0.5f, 1.0f);
    glUniform4f(ambientUniform, 0.1f, 0.1f, 0.1f, 1.0f);

    // render!
    renderSphere();

    // display rendering buffer
    SDL_GL_SwapBuffers();
}
Example #19
0
  Graphics::Graphics() {
	glewExperimental = GL_TRUE;
    glewInit();

    glGenVertexArrays(1, &vertexArray);
    glBindVertexArray(vertexArray);

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);

    fragShader = new FragmentShader("data/fragment.glsl");
    vertShader = new VertexShader("data/vertex.glsl");
    shaderProgram = new ShaderProgram();

    shaderProgram->setFragmentShader(fragShader);
    shaderProgram->setVertexShader(vertShader);

    shaderProgram->addBinding(0, "inVertex");
    shaderProgram->addBinding(1, "inTexCoord");
    shaderProgram->addBinding(2, "inColour");

    shaderProgram->link();
    shaderProgram->makeActive();

    modelMatrixUniform = shaderProgram->getUniformLocation("inModelMatrix");
    projectionMatrixUniform = shaderProgram->getUniformLocation("inProjectionMatrix");
    viewMatrixUniform = shaderProgram->getUniformLocation("inViewMatrix");
    texUniform = shaderProgram->getUniformLocation("inTexture");

    setMatrixMode(MatrixMode::MODEL);
    loadIdentity();

    setMatrixMode(MatrixMode::VIEW);
    loadIdentity();

    setMatrixMode(MatrixMode::PROJECTION);
    loadIdentity();
    //ortho(-8, 8, -8, 8, 0, 0);
    frustum(-(1 + ((3.0 / 4.0) / 2.0)), 1 + ((3.0 / 4.0) / 2.0), -1, 1, 1, 512);

    setMatrixMode(MatrixMode::MODEL);

    ResourceManager* rm = ResourceManager::getInstance();
    
    floorMesh = rm->getResource("data/model.obj")->toOBJModel()->compose();
    wallMesh = rm->getResource("data/wall.obj")->toOBJModel()->compose();
    ceilingMesh = rm->getResource("data/ceiling.obj")->toOBJModel()->compose();
    
    font = rm->getResource("data/DejaVuSansMono.ttf")->toFont();
    if (!font) {
      //  Throw an error;
      throw std::runtime_error("Graphics::Graphics():  Could not load font.");
    }
  }
Example #20
0
void init(void)
{

        skybox = LoadModelPlus("skybox.obj");
        sphere = LoadModelPlus("groundsphere.obj");


        // GL inits
	glClearColor(0.2,0.2,0.5,0);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	printError("GL inits");

	frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 200.0, projectionMatrix);
	
	cam_pos.x = 108.0f;
	cam_pos.y = 60.0f;
	cam_pos.z = 144.0f;
	up.x = 0;
	up.y = 1;
	up.z = 0;
	
	// Load and compile shader
	program = loadShaders("terrain.vert", "terrain.frag");
	glUseProgram(program);
	printError("init shader");
	
	glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix);
	glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0
	LoadTGATextureSimple("dirt.tga", &tex1);

        

        // Init light
        
        Point3D lightSourcesColorsArr = {0.5f, 0.5f, 0.5f}; // Grey light
        GLfloat specularExponent = 2.0;
        GLint isDirectional = 1;
        Point3D lightSourcesDirectionsPositions = {0.5f, 1.0f, 0.5f}; // grey light, positional

        glUniform3fv(glGetUniformLocation(program, "lightSourcesDirPosArr"), 1, &lightSourcesDirectionsPositions.x);
        glUniform3fv(glGetUniformLocation(program, "lightSourcesColorArr"), 1, &lightSourcesColorsArr.x);
        glUniform1f(glGetUniformLocation(program, "specularExponent"), specularExponent);
        glUniform1i(glGetUniformLocation(program, "isDirectional"), isDirectional);

        // Load terrain data
	
	LoadTGATexture("fft-terrain.tga", &ttex);
	tm = GenerateTerrain(&ttex);
	printError("init terrain");

        // Load textures	
        LoadTGATextureSimple("SkyBox512.tga", &skytex);
        LoadTGATextureSimple("grass.tga", &spheretex);
}
Example #21
0
void Camera::getClipPlanes
   (const Rect2D&       viewport,
    Array<Plane>&       clip) const {

    Frustum fr;
    frustum(viewport, fr);
    clip.resize(fr.faceArray.size(), DONT_SHRINK_UNDERLYING_ARRAY);
    for (int f = 0; f < clip.size(); ++f) {
        clip[f] = fr.faceArray[f].plane;
    }
}
Example #22
0
//Perspective
void perspective(float fovy, float aspect,
                 float zNear, float zFar) {
    float xmin, xmax, ymin, ymax;
    
    ymax = zNear * (float)tanf(fovy * M_PI / 360.0f);
    ymin = -ymax;
    xmin = ymin * aspect;
    xmax = ymax * aspect;
    
    frustum(xmin, xmax,ymin,ymax,zNear,zFar);
}
void LightsourceSimplePass::find_lights(GraphicContext &gc, Scene_Impl *scene)
{
	lights.clear();

	Size viewport_size = viewport->get_size();

	Mat4f eye_to_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 1.e10f, handed_left, gc.get_clip_z_range());
	Mat4f eye_to_cull_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 150.0f, handed_left, clip_negative_positive_w);
	FrustumPlanes frustum(eye_to_cull_projection * world_to_eye.get());
	scene->visit_lights(gc, world_to_eye.get(), eye_to_projection, frustum, this);
}
Example #24
0
void camerahdl::view(framehdl &frame, float ratio, float front, float back)
{
	frame.projection = frustum(-ratio, ratio, -1.0f, 1.0f, front, back);

	frame.modelview = identity<float, 4, 4>();
	if (link != NULL)
		frame.modelview *= rotate_xyz(-link->orientation);
	frame.modelview *= rotate_xyz(-orientation);

	frame.modelview *= translate(-(vec3f)position);
}
Example #25
0
mat4 & perspective(mat4& M, const nv_scalar fovy, const nv_scalar aspect, const nv_scalar n, const nv_scalar f)
{
    nv_scalar xmin, xmax, ymin, ymax;

    ymax = n * tan(fovy * nv_to_rad * nv_zero_5);
    ymin = -ymax;

    xmin = ymin * aspect;
    xmax = ymax * aspect;

    return frustum(M, xmin, xmax, ymin, ymax, n, f);
}
Example #26
0
void TilemapComponent::onRender(RenderingContext* context)
{
    Matrix worldInverse = Matrix::makeInverse(worldObject()->worldMatrix());
    Matrix viewLocal = context->viewPoint()->worldMatrix * worldInverse;

    Matrix viewMatrix = Matrix::makeLookAtLH(viewLocal.position(), viewLocal.position() + viewLocal.front(), viewLocal.up());
    ViewFrustum frustum(viewMatrix * context->viewPoint()->projMatrix);

    // ひとまず、 Z- を正面とする
    Plane plane(transrom()->position(), -transrom()->getFront());

    // TODO: 原点と正面方向
    Vector3 corners[8];
    Vector3 pt;
    frustum.getCornerPoints(corners);

    // TileMap の平面とカメラの視錐台から描画するべき範囲を求める
    detail::TilemapBounds bounds;
    for (int i = 0; i < 4; ++i)
    {
        if (plane.intersects(corners[i], corners[i + 4], &pt))
        {
            // pt をそのまま使う
        }
        else
        {
            // XY 平面上での最遠点を求める
            Vector2 pt2 = Vector2::normalize(corners[i + 4].xy() - corners[i].xy()) * context->viewPoint()->farClip;
            pt = Vector3(pt2, 0);
        }

        if (i == 0)
        {
            bounds.l = pt.x;
            bounds.t = pt.y;
            bounds.r = pt.x;
            bounds.b = pt.y;
        }
        else
        {
            bounds.l = std::min(bounds.l, pt.x);
            bounds.r = std::max(bounds.r, pt.x);
            bounds.t = std::max(bounds.t, pt.y);
            bounds.b = std::min(bounds.b, pt.y);
        }
    }

    
    m_tilemap->render(context, worldObject()->worldMatrix(), bounds);

    //context->drawSprite(Matrix::Identity, Size(5, 5), Vector2::Zero, Rect(0, 0, 1, 1), Color::White, SpriteBaseDirection::ZMinus, BillboardType::None, m_material);
}
Example #27
0
void GLAPIENTRY
gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
   GLfloat xmin, xmax, ymin, ymax;

   ymax = zNear * tan(fovy * M_PI / 360.0);
   ymin = -ymax;
   xmin = ymin * aspect;
   xmax = ymax * aspect;

   /* don't call glFrustum() because of error semantics (covglu) */
   frustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
Example #28
0
//Constructor
Camera::Camera(vec3 pos, GLfloat vel, GLfloat sens, vector<vector<TerrainPatch*>> * terrain, int sizePatch, int overlap,int sizeGrid)
{
  vec3 r = vec3(0.5,0,0);
  position = pos;
  lookAtPoint = VectorAdd(position,r);
  upVector = vec3(0.0,1.0,0.0);
  
  //Terrain information
  terrainVector = terrain;
  patchSize = sizePatch;
  patchOverlap = overlap;
  blendedSize = patchSize-patchOverlap;
  gridSize = sizeGrid;
  //Set inital patch not to equal to starting patch for comparison in  
  actualPatchXIndex = 100;
  actualPatchZIndex = 100;
  groundOffset = 10;
  flying = false;


  //cameraMatrix = lookAtv(position,lookAtPoint,upVector);
  velocity = 1.5;

  projectionNear = 0.8;
#if LOWGRAPHICS == 1
  projectionFar = 800.0;  
#else 
  projectionFar = 1700.0;
#endif
  projectionRight = 0.5/0.75; // for wide screen
  projectionLeft = -0.5/0.75; // for wide screen
  projectionTop = 0.5;
  projectionBottom = -0.5;

  warpPointer=true;
  lockFrustum=false;
  initKeymapManager();

  cameraMatrix = lookAtv(position,lookAtPoint,upVector);
  velocity = vel;
  sensitivity = sens;

  projectionMatrix = frustum(projectionLeft, projectionRight, projectionBottom, projectionTop,projectionNear, projectionFar);

  frustumPlanes = new Frustum(this);

  timer = 30;
  followFlock = false;
  birdView = true;
  flockIndex = -1; // Is set to zero first time we choose to follow a flock.
}
static void
perspective (GLfloat fovy,
	     GLfloat aspect,
	     GLfloat zNear,
	     GLfloat zFar)
{
   GLfloat xmin, xmax, ymin, ymax;

   ymax = zNear * tan (fovy * M_PI / 360.0);
   ymin = -ymax;
   xmin = ymin * aspect;
   xmax = ymax * aspect;

   frustum (xmin, xmax, ymin, ymax, zNear, zFar);
}
Example #30
0
void TileRender::setMatrices( const cinder::Camera &camera )
{
	float left, top, right, bottom, nearPlane, farPlane;
	camera.getFrustum( &left, &top, &right, &bottom, &nearPlane, &farPlane );

	if( camera.isPersp() ) {
		frustum( left, right, bottom, top, nearPlane, farPlane );
	}
	else {
		ortho( left, right, bottom, top, nearPlane, farPlane );
	}

	glMatrixMode( GL_MODELVIEW );
	glLoadMatrixf( camera.getModelViewMatrix().m );
}