예제 #1
0
파일: glview.cpp 프로젝트: kiyoya/sociarium
 bool GLView::scr2world_z0(Vector2<double>& pos, Vector2<int> const& scr) const {
   push_matrix();
   initialize_matrix();
   set_perspective_matrix();
   double model[16], proj[16];
   int view[4];
   glGetDoublev(GL_MODELVIEW_MATRIX, model);
   glGetDoublev(GL_PROJECTION_MATRIX, proj);
   glGetIntegerv(GL_VIEWPORT, view);
   Vector3<double> v; // マウス座標に対応するカメラのznear面上のワールド座標
   gluUnProject(GLdouble(scr.x), GLdouble(scr.y), 0.0, model, proj, view, &v.x, &v.y, &v.z);
   // 透視射影の場合(正射影の場合は単純に(v.x, v.y))
   if ((0.0<v.z && v.z<eye_.z) || (eye_.z<v.z && v.z<0.0)) {
     // 視線の先がz=0平面に交わる場合
     double const denom = eye_.z-v.z;
     pos.set((eye_.z*v.x-v.z*eye_.x)/denom, (eye_.z*v.y-v.z*eye_.y)/denom);
     pop_matrix();
     return true;
   } else {
     // 交わらない場合
     pos.set(v.x-eye_.x, v.y-eye_.y);
     pop_matrix();
     return false;
   }
 }
예제 #2
0
	GLuint Normals(std::vector<T>& dest) const
	{
		dest.resize(((_rings + 2) * (_sections + 1)) * 3);
		unsigned k = 0;
		//
		GLdouble r_step = (1.0 * math::Pi()) / GLdouble(_rings + 1);
		GLdouble s_step = (2.0 * math::Pi()) / GLdouble(_sections);

		for(unsigned r=0; r!=(_rings+2);++r)
		{
			GLdouble r_lat = std::cos(r*r_step);
			GLdouble r_rad = std::sin(r*r_step);
			// the sections
			for(unsigned s=0; s!=(_sections+1);++s)
			{
				dest[k++] = T(r_rad *  std::cos(s*s_step));
				dest[k++] = T(r_lat);
				dest[k++] = T(r_rad * -std::sin(s*s_step));
			}
		}
		//
		assert(k == dest.size());
		// 3 values per vertex
		return 3;
	}
예제 #3
0
파일: view.cpp 프로젝트: nobbk/copo
/// returns the selected face, NULL if nothing selected
view::face* view::get_selected_face(int x, int y) {
	GLuint select_buf[SELECT_BUF_SIZE];
	glSelectBuffer(SELECT_BUF_SIZE, select_buf);
	glRenderMode(GL_SELECT);
	glInitNames();
	GLdouble projection_matrix[16];
	glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);
	gluPickMatrix (GLdouble(x), GLdouble(viewport[3] - y), SELECT_TOL, SELECT_TOL, viewport);
	glMultMatrixd(projection_matrix);
	basemesh_drawable->render_faces();
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixd(projection_matrix);
	glFlush();
	GLint hits = glRenderMode(GL_RENDER);
	if (hits > 0) {
		int selected_face = select_buf[3];
		int depth = select_buf[1];
		for (int i = 1; i < hits; i++) {
			if (select_buf[i*4+1] < GLuint(depth))  {
				selected_face = select_buf[i*4+3];
				depth = select_buf[i*4+1];
			}
		}
		return (face*)selected_face;
	}
	return NULL;
}
예제 #4
0
	GLuint Bitangents(std::vector<T>& dest) const
	{
		dest.resize(((_rings + 2) * (_sections + 1)) * 3);
		unsigned k = 0;
		//
		GLdouble r_step = (1.0 * math::Pi()) / GLdouble(_rings + 1);
		GLdouble s_step = (2.0 * math::Pi()) / GLdouble(_sections);

		GLdouble ty = 0.0;
		for(unsigned r=0; r!=(_rings+2);++r)
		{
			GLdouble r_lat = std::cos(r*r_step);
			GLdouble r_rad = std::sin(r*r_step);
			GLdouble ny = r_lat;
			// the sections
			for(unsigned s=0; s!=(_sections+1);++s)
			{
				GLdouble tx = -std::sin(s*s_step);
				GLdouble tz = -std::cos(s*s_step);
				GLdouble nx = -r_rad * tz;
				GLdouble nz =  r_rad * tx;

				dest[k++] = T(ny*tz-nz*ty);
				dest[k++] = T(nz*tx-nx*tz);
				dest[k++] = T(nx*ty-ny*tx);
			}
		}
		//
		assert(k == dest.size());
		// 3 values per vertex
		return 3;
	}
예제 #5
0
파일: main.cpp 프로젝트: buihaduong/Origami
void reshape( int w, int h ) {
    glViewport( 0, 0, w, h );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0, GLdouble(w)/GLdouble(h), 1.0, 10000.0 );
    View.lookAt( 0, 0, 40,  0, 0, 0,  0, 1, 0 ); //eye, target, up
}
예제 #6
0
void renderCursor()
{
    //printf("Cursor redraw\n");
    // switch to orthogonal projection for the cursor
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, GLdouble(Width), 0, GLdouble(Height), -1.0f, 1.0f);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    // render the cursor
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    glBegin(GL_TRIANGLES);
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    glVertex2i(m_mouseX, m_mouseY);
    glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
    glVertex2i(m_mouseX + 16, m_mouseY - 32);
    glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
    glVertex2i(m_mouseX + 32, m_mouseY - 16);
    glEnd();
    
    glDisable(GL_BLEND);
    
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    
    glMatrixMode(GL_MODELVIEW);
}
void CircleGeometryRenderer::renderTeleported( const Eigen::Matrix<GLdouble,3,1>& color )
{
  glPushMatrix();
  glScaled( GLdouble( m_circle_geo.r() ), GLdouble( m_circle_geo.r() ), GLdouble( 1.0 ) );
  m_circle_renderer.renderCircleOutline( color );
  glPopMatrix();
}
예제 #8
0
void StGLRootWidget::stglResize(const StGLBoxPx& theRectPx) {
    const bool isChanged = getRectPx().right()  != theRectPx.width()
                        || getRectPx().bottom() != theRectPx.height();

    myProjCamera.resize(*myGlCtx, theRectPx.width(), theRectPx.height());

    changeRectPx().right()  = theRectPx.width();  // (left, top) forced to zero point (0, 0)
    changeRectPx().bottom() = theRectPx.height();

    myProjCamera.getZParams(myRectGl);
    myScaleGlX = (myRectGl.right() - myRectGl.left()) / GLdouble(getRectPx().width());
    myScaleGlY = (myRectGl.top() - myRectGl.bottom()) / GLdouble(getRectPx().height());

    myScrProjMat = myProjCamera.getProjMatrix();
    myScrProjMat.translate(StGLVec3(0.0f, 0.0f, -myProjCamera.getZScreen()));

    if(myMenuProgram->isValid()) {
        myMenuProgram->use(*myGlCtx);
        myMenuProgram->setProjMat(*myGlCtx, getScreenProjection());
        myMenuProgram->unuse(*myGlCtx);
    }

    // update all child widgets
    if(isChanged) {
        StGLWidget::stglResize();
    }
}
예제 #9
0
vec3 UnProject(float winz)
{
	GLdouble x=0.0, y=0.0, z=0.0;

	GLint MouseX = g_Input.MouseX;
	GLint MouseY = g_Input.MouseY;

	GLdouble modelMatrix[16];
	GLdouble projMatrix[16];
	GLint viewport[4];

	// Get the modelview matrix
	glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);

	// Get the projection matrix
	glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);

	// Fill out the viewport matrix
	glGetIntegerv(GL_VIEWPORT, viewport);

	// Get the window coordinates of the mouse cursor
	GLdouble winx = GLdouble(MouseX);
	GLdouble winy = GLdouble( viewport[3] - MouseY - 1 );

	// Perform the unproject
	gluUnProject(winx, winy, winz, modelMatrix, projMatrix, viewport, &x, &y, &z);

	return vec3( float(x), float(y), float(z) );
}
예제 #10
0
int Tetrahedron::faceAtPosition(const QPoint &pos)
{
    const int MaxSize = 512;
    GLuint buffer[MaxSize];
    GLint viewport[4];

    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(MaxSize, buffer);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()),
                  5.0, 5.0, viewport);
    GLfloat x = GLfloat(width()) / height();
    glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
    draw();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    if (!glRenderMode(GL_RENDER))
        return -1;
    return buffer[3];
}
예제 #11
0
파일: Mimicry.cpp 프로젝트: mohiul/mimicry
/**
* Adjust the projection matrix.
* \a viewingAngle is set by a GLUI control.
*/
void setProjection()
{
	glutSetWindow(modelWindow);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(viewingAngle, GLdouble(hModel)/GLdouble(wModel), NEAR_PLANE, FAR_PLANE);
    glutPostRedisplay();
}
예제 #12
0
void Reshape(int width, int height)
{
  glViewport(0, 0, width, height);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45., GLdouble(width)/GLdouble(height), 0.1, 100.);

  glMatrixMode(GL_MODELVIEW);
}
예제 #13
0
/* 2D */
void GLWidget::resizeGL( int w, int h )
{
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho(0.0,GLdouble(w),0,GLdouble(h),-10000.0,10000.0);
    glFlush();
    glMatrixMode(GL_MODELVIEW);
    glViewport( 0, 0, (GLint)w, (GLint)h );
    //cerr << "gl new size "<< w SEP h NL;
    renderWidth = w;
    renderHeight = h;
}
예제 #14
0
// Uses the last GL matrices set in set_perspective to project a point from
// screen coordinates to the agent's region.
void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 screen_y, LLVector3* pos_agent) const
{

	GLdouble x, y, z;
	gluUnProject(
		GLdouble(screen_x), GLdouble(screen_y), 0.0,
		gGLModelView, gGLProjection, (GLint*)gGLViewport,
		&x,
		&y,
		&z );
	pos_agent->setVec( (F32)x, (F32)y, (F32)z );
}
예제 #15
0
void StGLProjCamera::getZParams(const GLdouble theZValue,
                                StRectD_t&     theSectRect) const {
    if(myIsPersp) {
        theSectRect.top() = GLdouble(myZoom) * theZValue * std::tan(ST_DTR_HALF * myFOVy);
    } else {
        // Z-value doesn't change the section
        theSectRect.top() = GLdouble(myZoom) * myFrustM.zNear;/// * std::tan(ST_DTR_HALF * myFOVy);
    }
    theSectRect.bottom() = -theSectRect.top();
    theSectRect.left()   = -myAspect * theSectRect.top();
    theSectRect.right()  = -theSectRect.left();
}
예제 #16
0
void RenderingWidget::resizeGL(int w, int h)
{
	h = (h == 0) ? 1 : h;

	ptr_arcball_->reSetBound(w, h);

	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0, GLdouble(w) / GLdouble(h), 0.001, 1000);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
예제 #17
0
//input plygonList must be in order - depicting a fill or void
int B9Tesselator::Triangulate( const std::vector<QVector2D>* polygonList, std::vector<QVector2D> *triangleStrip)
{

        unsigned long int i;
        GLUtesselator *tess = gluNewTess(); // create a tessellator
        if(!tess) return 0;  // failed to create tessellation object, return 0


        this->triStrip = triangleStrip;
        this->CombineVertexIndex = 0;

        numPolyVerts = polygonList->size();
        polyverts = new GLdouble*[polygonList->size()];

        for(i = 0; i < polygonList->size(); i++)
        {
            polyverts[i] = new GLdouble[3];
            polyverts[i][0] = GLdouble(polygonList->at(i).x());
            polyverts[i][1] = GLdouble(polygonList->at(i).y());
            polyverts[i][2] = GLdouble(0.0);//zero in the z
        }

        gluTessProperty(tess, GLU_TESS_WINDING_RULE,
                           GLU_TESS_WINDING_NONZERO);
        gluTessNormal(tess, 0, 0, 1);

        // register callback functions
        gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (void (CALLBACK *)())tessBeginCB);
        gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK *)())tessEndCB);
        gluTessCallback(tess, GLU_TESS_ERROR_DATA, (void (CALLBACK *)())tessErrorCB);
        gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (void (CALLBACK *)())tessVertexCB);
        gluTessCallback(tess, GLU_TESS_COMBINE_DATA, (void (CALLBACK *)())tessCombineCB);


        gluTessBeginPolygon(tess, (void*) this);
            gluTessBeginContour(tess);
            for(i = 0; i < numPolyVerts; i++)
            {
                gluTessVertex(tess, polyverts[i], polyverts[i]);
            }
            gluTessEndContour(tess);
        gluTessEndPolygon(tess);


        gluDeleteTess(tess);        // delete after tessellation

        return !(int)memoryFull;
}
예제 #18
0
//------------------------------------------------------------------------------
// drawFunc() -- draws the object(s) using openGL
//------------------------------------------------------------------------------
void BearingPointer::drawFunc()
{
    GLfloat ocolor[4];
    GLfloat lw;
    glGetFloatv(GL_CURRENT_COLOR, ocolor);
    glGetFloatv(GL_LINE_WIDTH, &lw);
    
    // draw a default head and tail graphic, unless one is given to us, then draw it
    myRadius = 0;
    bool amICentered = isCentered();
    if (amICentered) myRadius = getCenteredRadius();
    else myRadius = getDeCenteredRadius();
    
    // now draw the head graphic
    glPushMatrix();
        // translate to the top of our radius
        glTranslated(0, GLdouble(myRadius), 0);
        if (head != 0) {
            head->container(this);
            head->draw();
        }
        else {
            glBegin(GL_POLYGON);
                glVertex2f(-0.5, 0);
                glVertex2f(0.5, 0);
                glVertex2f(0, 0.5);
            glEnd();
        }
    glPopMatrix();
    // now draw the tail graphic
    glPushMatrix();
        // translate to the bottom of our radius
        glTranslated(0, GLdouble(-myRadius), 0);
        if (tail != 0) {
            tail->container(this);
            tail->draw();
        }
        else {
            glLineWidth(3);
            glBegin(GL_LINES);
                glVertex2f(0, 0);
                glVertex2f(0, -0.5);
            glEnd();
        }
    glPopMatrix();
    glColor4fv(ocolor);
    glLineWidth(lw);
}
예제 #19
0
void Circulo::crearLados(){

	GLdouble cx = centro.x;
	GLdouble cy = centro.y;

	
		for(int i = 0; i < 20; i++) 
		{ 
			GLdouble theta = 2.0f * 3.1415926f * GLdouble(i) / GLdouble(20);//get the current angle 

			GLdouble x = radio * cos(theta);//calculate the x component 
			GLdouble y = radio * sin(theta);//calculate the y component 

			lados[i] = PV2D(x + cx,y + cy);
		}
}
예제 #20
0
void COpenGLView::InitCameraPosition()
{
  for(int i = 0; i < 16; i++)
    m_rotate[i] = GLdouble(i/4 == i%4);
  for(i = 0; i < 3; i++)
    m_translate[i] = 0;
}
예제 #21
0
파일: scm-cache.cpp 프로젝트: rlk/scm
void scm_cache::render(int ii, int nn)
{
    glPushAttrib(GL_ENABLE_BIT);
    {
        GLint v[4];

        glGetIntegerv(GL_VIEWPORT, v);

        const GLdouble a = GLdouble(v[3]) / GLdouble(v[2]);

        glDisable(GL_LIGHTING);
        glDisable(GL_DEPTH_TEST);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);

        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        glOrtho(0, nn, 0, nn * a, -1, +1);

        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();

        glUseProgram(0);
        glBindTexture(GL_TEXTURE_2D, texture);
        glColor4f(1.f, 1.f, 1.f, 1.f);

        glBegin(GL_QUADS);
        {
            GLfloat a = 0.05f;
            GLfloat b = 0.95f;

            glTexCoord2i(0, 1); glVertex2f(ii + a, a);
            glTexCoord2i(1, 1); glVertex2f(ii + b, a);
            glTexCoord2i(1, 0); glVertex2f(ii + b, b);
            glTexCoord2i(0, 0); glVertex2f(ii + a, b);
        }
        glEnd();

        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
    }
    glPopAttrib();
}
예제 #22
0
파일: HUD.cpp 프로젝트: Valyao0823/3DCube
void HUD::operate(int kill,int remaining) {
	
	glDisable(GL_CULL_FACE);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_ALPHA_TEST);

	glClear(GL_DEPTH_BUFFER_BIT);
  
	glViewport(0, 0, screen_width, screen_height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, screen_width, screen_height, 0, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	
	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, 4, u2, v2, 0, GL_RGBA, GL_UNSIGNED_BYTE, &crosshair[0]);
	glColor4ub(255, 255, 255, 255);
	int offsetW = screen_width/2;
	int offsetH = screen_height/2;	
	 glBegin(GL_QUADS);
	 glTexCoord2d( 0,  0); glVertex2f(offsetW - width/2,offsetH - height/2);
	 glTexCoord2d(u3,  0); glVertex2f(offsetW + width/2,offsetH - height/2);
	 glTexCoord2d(u3, v3); glVertex2f(offsetW + width/2,offsetH + height/2);
	 glTexCoord2d( 0, v3); glVertex2f(offsetW - width/2, offsetH + height/2);
	 glEnd();
	 glDisable(GL_TEXTURE_2D);

	 glutPrint(0, 18,combineChar("Kill Count",itoa(kill,buffer,10)), 0.0f, 1.0f, 0.0f, 1.0f);
	 glutPrint(0, 36,itoa(remaining,buffer,10), 0.0f, 1.0f, 0.0f, 1.0f);

	glViewport(0, 0, screen_width, screen_height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, GLdouble (screen_width), 0, GLdouble (screen_height));
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_ALPHA_TEST);
	glDisable(GL_BLEND);
		
}
예제 #23
0
GLColorMap& GLColorMap::setScalarRange(GLdouble newMin,GLdouble newMax)
	{
	min=newMin;
	max=newMax;
	factor=GLdouble(numEntries-1)/(max-min);
	offset=min*factor;
	
	return *this;
	}
예제 #24
0
void winReshapeFcn(GLint newWidth, GLint newHeight){
	glViewport(0, 0, newWidth, newHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0,  GLdouble(newWidth),  0.0,  newHeight);

	winWidth = newWidth;
	winHeight = newHeight;
}
예제 #25
0
void PerspectiveCameraController::setPerspective( const int width, const int height )
{
  const GLdouble fovy{ 54.43 };
  const GLdouble aspect{ GLdouble( width ) / GLdouble( height ) };
  const GLdouble z_near{ 0.1 };
  const GLdouble z_far{ 1000.0 };

  glViewport( 0, 0, width, height );

  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();

  // TODO: Off by a factor of 2?
  const GLdouble top{ tan( fovy / 360.0 * MathDefines::PI<GLdouble>() ) * z_near };
  const GLdouble right{ top * aspect };
  glFrustum( -right, right, -top, top, z_near, z_far );
  m_fovy = fovy;
  m_aspect = aspect;
}
예제 #26
0
//
// ウィンドウのサイズ変更時の処理
//
void Window::resize(GLFWwindow *window, int width, int height)
{
  // このインスタンスの this ポインタを得る
  Window *const instance(static_cast<Window *>(glfwGetWindowUserPointer(window)));

  if (instance)
  {
    // ウィンドウ全体をビューポートにする
    glViewport(0, 0, width, height);

    // 投影変換行列を初期化する
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fovy, GLdouble(width) / GLdouble(height), zNear, zFar);

    // トラックボール処理の範囲を設定する
    instance->tb.region(width, height);
  }
}
예제 #27
0
	GLuint TexCoordinates(std::vector<T>& dest) const
	{
		dest.resize(((_rings + 2) * (_sections + 1)) * 2);
		unsigned k = 0;
		//
		GLdouble r_step = 1.0 / GLdouble(_rings + 1);
		GLdouble s_step = 1.0 / GLdouble(_sections);
		for(unsigned r=0; r!=(_rings+2);++r)
		{
			GLdouble r_lat = 1.0 - r*r_step;
			// the sections
			for(unsigned s=0; s!=(_sections+1);++s)
			{
				dest[k++] = T(s * s_step);
				dest[k++] = T(r_lat);
			}
		}
		assert(k == dest.size());
		// 2 values per vertex
		return 2;
	}
예제 #28
0
void World::BuildGLMatrices()
{
    //glGetIntegerv(GL_VIEWPORT, viewport);

    // Projection Matrix
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    int nViewportWidth = viewport[2];
    int nViewportHeight = viewport[3];

    GLdouble fAspect = GLdouble(nViewportWidth) / GLdouble(nViewportHeight);

    //gluPerspective(m_fFieldOfView, fAspect, 0.1f, 20000.0f);
    //gluPerspective(m_fFieldOfView, fAspect, 0.01f, 1000.0f);
    //gluPerspective(m_fFieldOfView, fAspect, 0.1f, 1000.0f);

    //gluPerspective(m_fFieldOfView, fAspect, 1.0f, 1000.0f);
    gluPerspective(m_fFieldOfView, fAspect, 1.0f, 2000.0f);

    // gluPerspective makes a "-Z is in" matrix. I prefer +Z.
    glScalef(1,1,-1);

    // Modelview Matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    mlTransform transform = m_trnCamera;

    transform.Invert();

    mlMatrix4x4 matCameraTransform(transform.GetMatrix());

    mlFloat * pCameraTransform = reinterpret_cast<mlFloat*>(&matCameraTransform);

    glLoadMatrixf(pCameraTransform);

    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
}
예제 #29
0
GLColorMap::GLColorMap(GLenum type,GLfloat alphaMax,GLfloat alphaGamma,GLdouble sMin,GLdouble sMax)
	:numEntries(0),entries(0),min(sMin),max(sMax)
	{
	/* Create entry array: */
	setNumEntries(256);
	
	/* Create the palette colors: */
	GLenum colorType=type&(GREYSCALE|RAINBOW);
	if(colorType==GREYSCALE)
		{
		for(GLsizei i=0;i<256;++i)
			{
			entries[i][0]=GLfloat(i)/255.0f;
			entries[i][1]=GLfloat(i)/255.0f;
			entries[i][2]=GLfloat(i)/255.0f;
			}
		}
	else if(colorType==RAINBOW)
		{
		for(GLsizei i=0;i<256;++i)
			{
			/* Create rainbow colors: */
			GLdouble rad=GLdouble(i)*(2.0*M_PI/256.0);
			if(rad<=2.0*M_PI/3.0)
				entries[i][0]=cos(0.75*rad);
			else if(rad>=4.0*M_PI/3.0)
				entries[i][0]=cos(0.75*(2.0*M_PI-rad));
			else
				entries[i][0]=0.0;
			entries[i][1]=sin(0.75*rad);
			if(entries[i][1]<0.0)
				entries[i][1]=0.0;
			entries[i][2]=sin(0.75*(rad-2.0*M_PI/3.0));
			if(entries[i][2]<0.0)
				entries[i][2]=0.0;
			}
		}
	
	/* Create the palette opacities: */
	GLenum alphaType=type&(CONSTANT_ALPHA|RAMP_ALPHA);
	if(alphaType==CONSTANT_ALPHA)
		{
		for(GLsizei i=0;i<256;++i)
			entries[i][3]=alphaMax;
		}
	else if(alphaType==RAMP_ALPHA)
		{
		double ag=double(alphaGamma);
		for(GLsizei i=0;i<256;++i)
			entries[i][3]=alphaMax*pow(double(i)/255.0,ag);
		}
	}
예제 #30
0
파일: main.cpp 프로젝트: henrical/CG
void reshape(int h, int w)
{
    GLdouble top, right, bottom, left, near_val, far_val;
    top = right = GLdouble(-2.0f);
    bottom = left = GLdouble(2.0f);
    near_val = GLdouble(-2.0f), far_val = GLdouble(2.0f);

    glViewport(10, 10, h, w);

    //Pushes Projection matrix to top of the stack.
    //Loads identity matrix.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    //Define projection.
    glOrtho(left, right, bottom, top, near_val, far_val);

    //Pushes Model-View matrix to top of the stack.
    //Loads identity matrix.
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}