Example #1
0
static void
frustum(GLdouble left, GLdouble right,
        GLdouble bottom, GLdouble top, 
        GLdouble nearval, GLdouble farval)
{
   GLdouble x, y, a, b, c, d;
   GLdouble m[16];

   x = (2.0 * nearval) / (right - left);
   y = (2.0 * nearval) / (top - bottom);
   a = (right + left) / (right - left);
   b = (top + bottom) / (top - bottom);
   c = -(farval + nearval) / ( farval - nearval);
   d = -(2.0 * farval * nearval) / (farval - nearval);

#define M(row,col)  m[col*4+row]
   M(0,0) = x;     M(0,1) = 0.0F;  M(0,2) = a;      M(0,3) = 0.0F;
   M(1,0) = 0.0F;  M(1,1) = y;     M(1,2) = b;      M(1,3) = 0.0F;
   M(2,0) = 0.0F;  M(2,1) = 0.0F;  M(2,2) = c;      M(2,3) = d;
   M(3,0) = 0.0F;  M(3,1) = 0.0F;  M(3,2) = -1.0F;  M(3,3) = 0.0F;
#undef M

   glMultMatrixd(m);
}
void CScanLineZBufferView::OnMouseMove(UINT nFlags, CPoint point)
{
	// std::cout << logTime() << " 当前屏幕坐标点:" << point.x << " " << point.y << std::endl;
	// 没有导入模型
	if ( GetDocument()->m_mesh.n_vertices() <= 0)	return;
	
	// 处理模型旋转事件
	// 保存上一次点击位置
	
	static CPoint prevPointPos(-1, -1);
	if (nFlags & MK_LBUTTON)
	{
		// std::cout << logTime() << " " << "Model Move" << std::endl;
		// std::cout << "(" << prevPointPos.x << ", " << prevPointPos.y << ")" << " " << "(" << point.x << ", " << point.y << ")" << std::endl;
		if (prevPointPos.x < 0 || prevPointPos.y < 0) prevPointPos = point; // 处理一次点击
		// 旋转模型
		double x = prevPointPos.x - point.x;
		double y = prevPointPos.y - point.y;
		double modelview_matrix[16];
		glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glTranslated(0., 0., m_z_delta); // 移动到原点
		glRotated(sqrt((double)(x*x + y*y)), y, x, 0.0); // 旋转
		glTranslated(0., 0., -m_z_delta); // 移回原处
		glMultMatrixd(modelview_matrix);
		prevPointPos = point;
		RedrawWindow();
	}
	else
	{
		prevPointPos.x = prevPointPos.y = -1;
	}
	
	// CView::OnMouseMove(nFlags, point);
}
//------------------------------------------------------------------------------
void drawOtherCamera()
{
	int i;


	// draw other cameras.
	for (i=0; i < (int)wld2cam.size(); i++ )
	{
		if (i != cameraIndex)
		{
			glPushMatrix();												// Push the current matrix on GL to stack. The matrix is wld2cam[cameraIndex].matrix().
			glMultMatrixd(cam2wld[i].GLmatrix());							// Multiply the matrix to draw i-th camera.
			drawFrame(5);											// Draw x, y, and z axis.
			float frontColor[] = {0.2, 0.2, 0.2, 1.0};
			glEnable(GL_LIGHTING);									
			glMaterialfv(GL_FRONT, GL_AMBIENT, frontColor);			// Set ambient property frontColor.
			glMaterialfv(GL_FRONT, GL_DIFFUSE, frontColor);			// Set diffuse property frontColor.
			glScaled(0.5,0.5,0.5);										// Reduce camera size by 1/2.
			glTranslated(1.1,1.1,0.0);									// Translate it (1.1, 1.1, 0.0).
			glCallList(camID);											// Re-draw using display list from camID. 
			glPopMatrix();												// Call the matrix on stack. wld2cam[cameraIndex].matrix() in here.
		}
	}
}
Example #4
0
void Object3D::draw(void)
{
    beforeTransformations();
    glMatrixMode(GL_MODELVIEW_MATRIX);
    glPushMatrix();

    glTranslatef(translation().x(), translation().y(), translation().z());
    glTranslatef(center().x(), center().y(), center().z());

    QQuaternion t = interactiveQuartenion();
    glRotatef(degreeFromCos(t.scalar()),
              0, 0, t.z());

    //glMultMatrixf(rotations().constData());
    glMultMatrixd(rotations().constData());

    m_modelView = glGetMatrix(GL_MODELVIEW_MATRIX);
    m_projection = glGetMatrix(GL_PROJECTION_MATRIX);

    afterTransformations();
    drawGeometry();

    glPopMatrix();
}
Example #5
0
 void drawVertexArrays(Float x1, Float y1, Float x2, Float y2, Float x3, Float y3, Float x4, Float y4) const
 {
     // TODO: Macros should not be split up just because they have different transforms! This is insane.
     // They should be premultiplied and have the same transform by definition. Then, the transformation
     // only had to be performed here once.
     
     #ifndef GOSU_IS_OPENGLES
     glEnable(GL_BLEND);
     glMatrixMode(GL_MODELVIEW);
     
     Transform transform =
         findTransformForTarget(x1, y1, x2, y2, x3, y3, x4, y4);
     
     for (VertexArrays::const_iterator it = vertexArrays.begin(), end = vertexArrays.end(); it != end; ++it)
     {
         glPushMatrix();
         it->renderState.apply();
         glMultMatrixd(&transform[0]);
         glInterleavedArrays(GL_T2F_C4UB_V3F, 0, &it->vertices[0]);
         glDrawArrays(GL_QUADS, 0, it->vertices.size());
         glPopMatrix();
     }
     #endif
 }
Example #6
0
static void blf_draw__start(FontBLF *font)
{
	/*
	 * The pixmap alignment hack is handle
	 * in BLF_position (old ui_rasterpos_safe).
	 */

	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glPushMatrix();

	if (font->flags & BLF_MATRIX)
		glMultMatrixd((GLdouble *)&font->m);

	glTranslatef(font->pos[0], font->pos[1], font->pos[2]);

	if (font->flags & BLF_ASPECT)
		glScalef(font->aspect[0], font->aspect[1], font->aspect[2]);

	if (font->flags & BLF_ROTATION)
		glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
}
Example #7
0
void CGlutWindow::renderFrame() {
    
	if (stereoSwitch != isStereo) {
		int w = glutGet( GLUT_WINDOW_WIDTH );
		int h = glutGet( GLUT_WINDOW_HEIGHT );
		resize(w,h);
	}
    
	stereoSwitch = isStereo;
    
	double dAspectRatio = double(m_nWidth)/double(m_nHeight);
    
	// The usual OpenGL stuff to clear the screen and set up viewing.
	glClearColor(.5, .5, 1., 1.);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
	GLfloat fTop, fRight, fNear, fFar;
    
	fNear   = float(m_dCenter - m_dRadius);
	fFar    = float(m_dCenter + m_dRadius);
    
	if (dAspectRatio > 1.0) {
		fRight = fNear * float(tan(DEG2RAD(m_dFieldOfView)/2.0) /m_dZoom);
		fTop   = fRight * float(dAspectRatio);		
	} else {
		fTop   = fNear * float(tan(DEG2RAD(m_dFieldOfView)/2.0) /m_dZoom);
		fRight = fTop / float(dAspectRatio);
	} 
    
	glViewport(0,0,m_nWidth,m_nHeight);
    
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum( -fTop, fTop, -fRight, fRight, fNear, 10*fFar);
    
	CMatrix matModel = m_pCameraArcball->getRotatonMatrix().getInverse();
    
	double matrix[16];
	matModel.get(matrix[ 0], matrix[ 4], matrix[ 8], matrix[12],
                 matrix[ 1], matrix[ 5], matrix[ 9], matrix[13],
                 matrix[ 2], matrix[ 6], matrix[10], matrix[14],
                 matrix[ 3], matrix[ 7], matrix[11], matrix[15]);
    
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
    
	glClear(GL_COLOR_BUFFER_BIT);
    
	//Set up window for stereo or non-stereo viewing
	for( int i=0; i <= (isStereo ? 1 : 0); ++i ) {
		
		if ( isStereo )	   
			glViewport(  i*(camera->getViewportWidthInPixels()), 0,
                       camera->getViewportWidthInPixels(),
                       camera->getViewportHeightInPixels());
		
		if (i == 0) camera->transform((isStereo ? CAMERA_LEFT : CAMERA_MONO), stereoDistance);
		else camera->transform(CAMERA_RIGHT, stereoDistance);
		glTranslated(m_dTranslateX * m_dRadius/(m_dZoom), m_dTranslateY*m_dRadius/(m_dZoom), 0);
		glMultMatrixd(matrix);
		renderGeometry();	
	}
	displayTF();
    
	glutSwapBuffers();
}
Example #8
0
void Scarry::draw(wardraw_t *wd){
	Scarry *const p = this;
	static int init = 0;
	static suftex_t *pst;
	static suf_t *sufbase = NULL;
	if(!w)
		return;

	/* cull object */
/*	if(beamer_cull(this, wd))
		return;*/
//	wd->lightdraws++;

	draw_healthbar(this, wd, health / getMaxHealth(), getHitRadius(), -1., capacitor / maxenergy());

	if(wd->vw->gc->cullFrustum(pos, getHitRadius()))
		return;
#if 0
	if(init == 0) do{
		init = 1;
		sufbase = CallLoadSUF("models/spacecarrier.bin");
		if(!sufbase) break;
		CallCacheBitmap("bridge.bmp", "bridge.bmp", NULL, NULL);
		CallCacheBitmap("beamer_panel.bmp", "beamer_panel.bmp", NULL, NULL);
		CallCacheBitmap("bricks.bmp", "bricks.bmp", NULL, NULL);
		CallCacheBitmap("runway.bmp", "runway.bmp", NULL, NULL);
		suftexparam_t stp;
		stp.flags = STP_MAGFIL | STP_MINFIL | STP_ENV;
		stp.magfil = GL_LINEAR;
		stp.minfil = GL_LINEAR;
		stp.env = GL_ADD;
		stp.mipmap = 0;
		CallCacheBitmap5("engine2.bmp", "engine2br.bmp", &stp, "engine2.bmp", NULL);
		pst = AllocSUFTex(sufbase);
		extern GLuint screentex;
		glNewList(pst->a[0].list, GL_COMPILE);
		glBindTexture(GL_TEXTURE_2D, screentex);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		glDisable(GL_LIGHTING);
		glEndList();
	} while(0);
	if(sufbase){
		static const double normal[3] = {0., 1., 0.};
		double scale = SCARRY_SCALE;
		static const GLdouble rotaxis[16] = {
			-1,0,0,0,
			0,1,0,0,
			0,0,-1,0,
			0,0,0,1,
		};
		Mat4d mat;

		glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT);
		glPushMatrix();
		transform(mat);
		glMultMatrixd(mat);

#if 1
		for(int i = 0; i < nhitboxes; i++){
			Mat4d rot;
			glPushMatrix();
			gldTranslate3dv(hitboxes[i].org);
			rot = hitboxes[i].rot.tomat4();
			glMultMatrixd(rot);
			hitbox_draw(this, hitboxes[i].sc);
			glPopMatrix();
		}
#endif

		Mat4d modelview, proj;
		glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
		glGetDoublev(GL_PROJECTION_MATRIX, proj);
		Mat4d trans = proj * modelview;
		texture((glPushMatrix(),
			glScaled(1./2., 1./2., 1.),
			glTranslated(1, 1, 0),
			glMultMatrixd(trans)
		));
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(1,0,0,0));
		glEnable(GL_TEXTURE_GEN_S);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,1,0,0));
		glEnable(GL_TEXTURE_GEN_T);
		glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeniv(GL_R, GL_EYE_PLANE, Vec4<int>(0,0,1,0));
		glEnable(GL_TEXTURE_GEN_R);
		glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1));
		glEnable(GL_TEXTURE_GEN_Q);

		glPushMatrix();
		glScaled(scale, scale, scale);
		glMultMatrixd(rotaxis);
		DecalDrawSUF(sufbase, SUF_ATR, NULL, pst, NULL, NULL);
		glPopMatrix();

		texture((glPopMatrix()));
		glPopMatrix();
		glPopAttrib();
	}
#endif
}
Example #9
0
void Camera::DrawSpike(double rad, const vector3d &viewCoords, const matrix4x4d &viewTransform)
{
	glPushMatrix();

	float znear, zfar;
	Render::GetNearFarClipPlane(znear, zfar);
	double newdist = znear + 0.5f * (zfar - znear);
	double scale = newdist / viewCoords.Length();

	glTranslatef(float(scale*viewCoords.x), float(scale*viewCoords.y), float(scale*viewCoords.z));

	Render::State::UseProgram(0);
	// face the camera dammit
	vector3d zaxis = viewCoords.Normalized();
	vector3d xaxis = vector3d(0,1,0).Cross(zaxis).Normalized();
	vector3d yaxis = zaxis.Cross(xaxis);
	matrix4x4d rot = matrix4x4d::MakeInvRotMatrix(xaxis, yaxis, zaxis);
	glMultMatrixd(&rot[0]);

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

	// XXX WRONG. need to pick light from appropriate turd.
	GLfloat col[4];
	glGetLightfv(GL_LIGHT0, GL_DIFFUSE, col);
	glColor4f(col[0], col[1], col[2], 1);
	glBegin(GL_TRIANGLE_FAN);
	glVertex3f(0,0,0);
	glColor4f(col[0], col[1], col[2], 0);

	const float spikerad = float(scale*rad);

	// bezier with (0,0,0) control points
	{
		vector3f p0(0,spikerad,0), p1(spikerad,0,0);
		float t=0.1f; for (int i=1; i<10; i++, t+= 0.1f) {
			vector3f p = (1-t)*(1-t)*p0 + t*t*p1;
			glVertex3fv(&p[0]);
		}
	}
	{
		vector3f p0(spikerad,0,0), p1(0,-spikerad,0);
		float t=0.1f; for (int i=1; i<10; i++, t+= 0.1f) {
			vector3f p = (1-t)*(1-t)*p0 + t*t*p1;
			glVertex3fv(&p[0]);
		}
	}
	{
		vector3f p0(0,-spikerad,0), p1(-spikerad,0,0);
		float t=0.1f; for (int i=1; i<10; i++, t+= 0.1f) {
			vector3f p = (1-t)*(1-t)*p0 + t*t*p1;
			glVertex3fv(&p[0]);
		}
	}
	{
		vector3f p0(-spikerad,0,0), p1(0,spikerad,0);
		float t=0.1f; for (int i=1; i<10; i++, t+= 0.1f) {
			vector3f p = (1-t)*(1-t)*p0 + t*t*p1;
			glVertex3fv(&p[0]);
		}
	}
	glEnd();
	glDisable(GL_BLEND);
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);
	glPopMatrix();
}
Example #10
0
void display(void)
{
	double orimat[16] = {0};

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();


	// The Scene begins
	win.mode3D();

	// Apply our orientation
	win.fillOrientationMatrix(orimat);
	glMultMatrixd(orimat);

	// Translate - in world space
	glTranslated(win.pos().x(), win.pos().y(), win.pos().z());

	// Some randomly colored cubes
	glColor3f(cubeCol[0], cubeCol[1], cubeCol[2]);
	glPushMatrix();
	glTranslated(2.0, 0.0, 0.0);
	glutSolidCube(0.5);
	glPopMatrix();

	glPushMatrix();
	glColor3f(cubeCol[3], cubeCol[4], cubeCol[5]);
	glTranslated(-2.0, 0.0, 0.0);
	glutSolidCube(0.5);
	glPopMatrix();

	glPushMatrix();
	glColor3f(cubeCol[6], cubeCol[7], cubeCol[8]);
	glTranslated(0.0, 0.0, 2.0);
	glutSolidCube(0.5);
	glPopMatrix();

	glPushMatrix();
	glColor3f(cubeCol[9], cubeCol[10], cubeCol[11]);
	glTranslated(0.0, 0.0, -2.0);
	glutSolidCube(0.5);
	glPopMatrix();

	// A big wiresphere
	glColor3f(1.0, 1.0, 1.0);
	glutWireSphere(32.0, 16, 16);


	// Simple 2D crosshair
	win.mode2D();

	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);

	glColor3f(1.0, 0.0, 0.0);
	glBegin(GL_LINES);
	glVertex2f(0.5 * win.w() - 5, 0.5 * win.h());
	glVertex2f(0.5 * win.w() + 5, 0.5 * win.h());
	glVertex2f(0.5 * win.w(), 0.5 * win.h() - 5);
	glVertex2f(0.5 * win.w(), 0.5 * win.h() + 5);
	glEnd();

	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);


	// We're done.
	glutSwapBuffers();
	glPopMatrix();
}
Example #11
0
void draw_arrow(
	float ax, float ay, float az,
	float bx, float by, float bz,
	float ah, float bh,
	char const * const annotation,
	float annot_size )
{
	int i;

	GLdouble mv[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, mv);
	
	/* We're assuming the modelview RS part is (isotropically scaled)
	 * orthonormal, so the inverse is the transpose.
	 * The local view direction vector is the 3rd column of the matrix;
	 * assuming the view direction to be the normal on the arrows tangent
	 * space  taking the cross product of this with the arrow direction
	 * yields the binormal to be used as the orthonormal base to the 
	 * arrow direction to be used for drawing the arrowheads */

	double d[3] = {
	      bx - ax,
	      by - ay,
	      bz - az
	};
	normalize_v(d);

	double r[3] = { mv[0], mv[4], mv[8] };
	int rev = scalarproduct_v(d, r) < 0.;

	double n[3] = { mv[2], mv[6], mv[10] };
	{
		double const s = scalarproduct_v(d,n);
		for(int i = 0; i < 3; i++)
			n[i] -= d[i]*s;
	}
	normalize_v(n);

	double b[3];
	crossproduct_v(n, d, b);

	GLfloat const pos[][3] = {
		{ax, ay, az},
		{bx, by, bz},
		{ ax + (0.866*d[0] + 0.5*b[0])*ah,
		  ay + (0.866*d[1] + 0.5*b[1])*ah,
		  az + (0.866*d[2] + 0.5*b[2])*ah },
		{ ax + (0.866*d[0] - 0.5*b[0])*ah,
		  ay + (0.866*d[1] - 0.5*b[1])*ah,
		  az + (0.866*d[2] - 0.5*b[2])*ah },
		{ bx + (-0.866*d[0] + 0.5*b[0])*bh,
		  by + (-0.866*d[1] + 0.5*b[1])*bh,
		  bz + (-0.866*d[2] + 0.5*b[2])*bh },
		{ bx + (-0.866*d[0] - 0.5*b[0])*bh,
		  by + (-0.866*d[1] - 0.5*b[1])*bh,
		  bz + (-0.866*d[2] - 0.5*b[2])*bh }
	};
	GLushort const idx_line[][2] = {
		{0, 1},
	};
	GLushort const idx_heads[][3] = {
		{0, 2, 3},
		{1, 4, 5}
	};
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, pos);

	glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, idx_line);
	glDrawElements(GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, idx_heads);
	glDisableClientState(GL_VERTEX_ARRAY);

	if(annotation) {
		float w = 0;
		for(char const *c = annotation; *c; c++)
			w += glutStrokeWidth(GLUT_STROKE_ROMAN, *c);
		w *= annot_size / 100.;

		float tx = (ax + bx)/2.;
		float ty = (ay + by)/2.;
		float tz = (az + bz)/2.;

		GLdouble r[16] = {
			d[0], d[1], d[2], 0,
			b[0], b[1], b[2], 0,
			n[0], n[1], n[2], 0,
			   0,    0,    0, 1
		};
		glPushMatrix();
		glTranslatef(tx, ty, tz);
		glMultMatrixd(r);
		if(rev)
			glScalef(-1, -1, 1);
		glTranslatef(-w/2., annot_size*0.1, 0);
		draw_strokestring(GLUT_STROKE_ROMAN, annot_size, annotation);
		glPopMatrix();
	}
}
Example #12
0
 void Camera::applyModelview() const
 {
   glMultMatrixd( d->modelview.data() );
 }
Example #13
0
void Viewpoint::setupOrientation(RenderContext* rctx) const
{
  glMultMatrixd(mouseMatrix);
  glMultMatrixd(userMatrix);

}
void Object::render()
{
    glMatrixMode(GL_MODELVIEW);
    glMultMatrixd(this->model2world.getPointer());
}
Example #15
0
static void zpr_motion(int x, int y) {
  bool changed = false;

  const int dx = x - _mousex;
  const int dy = y - _mousey;

  GLint viewport[4];
  glGetIntegerv(GL_VIEWPORT, viewport);

  if(dx == 0 && dy == 0) return;

  if(_mouse_middle || _mouse_right) {
    double s = exp((double)dy * 0.01);

    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2] );
    glscale *= s;
    glScalef(s, s, s);
    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2]);

    changed = true;
  }
  else if(_mouse_left) {
    double ax, ay, az;
    double bx, by, bz;
    double angle;

    ax = dy;
    ay = dx;
    az = 0.0;
    angle = vlen(az, ay, az) / (double)(viewport[2]+1)*180.0;

    // Use inverse matrix to determine axis of rotation.
    bx = _matrix_inverse[0] * ax + _matrix_inverse[4] * ay + _matrix_inverse[8]   * az;
    by = _matrix_inverse[1] * ax + _matrix_inverse[5] * ay + _matrix_inverse[9]   * az;
    bz = _matrix_inverse[2] * ax + _matrix_inverse[6] * ay + _matrix_inverse[10]  * az;

    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2]);
    glRotatef(angle, bx, by, bz);
    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2]);

    changed = true;
  }
  else if(0 && _mouse_right) {
    double px, py, pz;

    pos(&px, &py, &pz, x, y, viewport);

    glLoadIdentity();
    glTranslatef(px - _drag_posx, py - _drag_posy, pz - _drag_posz);
    glMultMatrixd(_matrix);

    _drag_posx = px;
    _drag_posy = py;
    _drag_posz = pz;

    changed = true;
  }
  _mousex = x;
  _mousey = y;

  if(changed) {
    reset_orientation = 0;
    get_matrix();
    glutPostRedisplay();
  }
}
Example #16
0
void
world_display(void)
{
    double length;
    float l[3];
    GLfloat pos[4], lKa[4], lKd[4], lKs[4];
    GLfloat dir[3], mKa[4], mKd[4], mKs[4], mKe[4];
    GLfloat lmKa[4];

    cell_vector(pos, light_pos, 4);
    cell_vector(lKa, light_Ka, 4);
    cell_vector(lKd, light_Kd, 4);
    cell_vector(lKs, light_Ks, 4);
    cell_vector(dir, spot_direction, 3);
    cell_vector(mKa, material_Ka, 4);
    cell_vector(mKd, material_Kd, 4);
    cell_vector(mKs, material_Ks, 4);
    cell_vector(mKe, material_Ke, 4);
    cell_vector(lmKa, lmodel_Ka, 4);

    glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, local_viewer.value);
    glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, two_side.value);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmKa);

    glMaterialfv(GL_FRONT, GL_AMBIENT, mKa);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mKd);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mKs);
    glMaterialfv(GL_FRONT, GL_EMISSION, mKe);
    glMaterialf(GL_FRONT, GL_SHININESS, material_Se.value);

    glLightfv(GL_LIGHT0, GL_AMBIENT, lKa);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lKd);
    glLightfv(GL_LIGHT0, GL_SPECULAR, lKs);
    glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, (int)spot_exponent.value);
    if (spot_cutoff.value > 90)
        glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 180);
    else
        glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, (int)spot_cutoff.value);
    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, Kc.value);
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl.value);
    glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq.value);

    l[0] = at[0] - eye[0];
    l[1] = at[1] - eye[1];
    l[2] = at[2] - eye[2];

    invert(modelview, inverse);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glMultMatrixd(inverse);
    glTranslatef(l[0], l[1], l[2]);
    glColor3fv(lKd);
    glBegin(GL_LINE_STRIP);
    if (spot_cutoff.value > 90)
        glVertex3f(0, 0, 0);
    else
        glVertex3f(pos[0]+spot_direction[0].value,
                   pos[1]+spot_direction[1].value,
                   pos[2]+spot_direction[2].value);

    if (pos[3] == 0)        /* 10.0 = 'infinite' light */
        glVertex3f(pos[0]*10.0,pos[1]*10.0,pos[2]*10.0);
    else
        glVertex3f(pos[0], pos[1], pos[2]);
    glEnd();
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glPopMatrix();

    length = normalize(l);

    if (world_draw) {
        glEnable(GL_LIGHTING);
        if (pmodel)
            drawmodel();
        else
            glutSolidTorus(0.25, 0.75, 28, 28);
        glDisable(GL_LIGHTING);
    }

#if 0
#define TESS 20
    glNormal3f(0.0, 1.0, 0.0);
    for (i = 0; i < TESS; i++) {
        glBegin(GL_TRIANGLE_STRIP);
        for (j = 0; j <= TESS; j++) {
            glVertex3f(-1+(float)i/TESS*2, -1.0, -1+(float)j/TESS*2);
            glVertex3f(-1+(float)(i+1)/TESS*2, -1.0, -1+(float)j/TESS*2);
        }
        glEnd();
    }
#endif

    glPushMatrix();
    glMultMatrixd(inverse);

    /* draw the axis and eye vector */
    glPushMatrix();
    glColor3ub(0, 0, 255);
    glBegin(GL_LINE_STRIP);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, -1.0*length);
    glVertex3f(0.1, 0.0, -0.9*length);
    glVertex3f(-0.1, 0.0, -0.9*length);
    glVertex3f(0.0, 0.0, -1.0*length);
    glVertex3f(0.0, 0.1, -0.9*length);
    glVertex3f(0.0, -0.1, -0.9*length);
    glVertex3f(0.0, 0.0, -1.0*length);
    glEnd();
    glColor3ub(255, 255, 0);
    glRasterPos3f(0.0, 0.0, -1.1*length);
    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'e');
    glColor3ub(255, 0, 0);
    glScalef(0.4, 0.4, 0.4);
    drawaxes();
    glPopMatrix();

    invert(projection, inverse);
    glMultMatrixd(inverse);

    /* draw the viewing frustum */
    glColor3f(0.2, 0.2, 0.2);
    glBegin(GL_QUADS);
    glVertex3i(1, 1, 1);
    glVertex3i(-1, 1, 1);
    glVertex3i(-1, -1, 1);
    glVertex3i(1, -1, 1);
    glEnd();

    glColor3ub(128, 196, 128);
    glBegin(GL_LINES);
    glVertex3i(1, 1, -1);
    glVertex3i(1, 1, 1);
    glVertex3i(-1, 1, -1);
    glVertex3i(-1, 1, 1);
    glVertex3i(-1, -1, -1);
    glVertex3i(-1, -1, 1);
    glVertex3i(1, -1, -1);
    glVertex3i(1, -1, 1);
    glEnd();

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(0.2, 0.2, 0.4, 0.5);
    glBegin(GL_QUADS);
    glVertex3i(1, 1, -1);
    glVertex3i(-1, 1, -1);
    glVertex3i(-1, -1, -1);
    glVertex3i(1, -1, -1);
    glEnd();
    glDisable(GL_BLEND);

    glPopMatrix();
    glutSwapBuffers();
}
Example #17
0
/* OpenGL draw function & timing */
static void draw(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  {
    // convert opengl coordinates into the document information coordinates
    glPushMatrix();
    glMultMatrixf((GLfloat*)m_convert);

    // apply view offset
    openMVG::Mat4 offset_w = l2w_Camera(Mat3::Identity(), Vec3(x_offset,y_offset,z_offset));
    glMultMatrixd((GLdouble*)offset_w.data());

    // then apply current camera transformation
    const PinholeCamera & camera = m_doc._map_camera.find(current_cam)->second;
    openMVG::Mat4 l2w = l2w_Camera(camera._R, camera._t);

    glPushMatrix();
    glMultMatrixd((GLdouble*)l2w.data());

    glPointSize(3);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);

    //Draw Structure in GREEN (as seen from the current camera)
    size_t nbPoint = m_doc._vec_points.size()/3;
    size_t cpt = 0;
    glBegin(GL_POINTS);
    glColor3f(0.f,1.f,0.f);
    for(size_t i = 0; i < nbPoint; i++,cpt+=3) {
      glVertex3f(m_doc._vec_points[cpt], m_doc._vec_points[cpt+1], m_doc._vec_points[cpt+2]);
    }
    glEnd();

    glDisable(GL_CULL_FACE);

    for (int i_cam=0; i_cam<m_doc._vec_imageNames.size(); ++i_cam)
    {
    		const PinholeCamera & camera_i = m_doc._map_camera.find(i_cam)->second;

    		// Move frame to draw the camera i_cam by applying its inverse transformation
    		// Warning: translation has to be "fixed" to remove the current camera rotation

    		// Fix camera_i translation with current camera rotation inverse
    		Vec3 trans = camera._R.transpose() * camera_i._t;

    		// compute inverse transformation matrix from local to world
    		openMVG::Mat4 l2w_i = l2w_Camera(camera_i._R.transpose(), -trans);

        // stack it and use it
    		glPushMatrix();
    		glMultMatrixd((GLdouble*)l2w_i.data());

    		// 1. Draw optical center (RED) and image center (BLUE)
    		glPointSize(3);
    		glDisable(GL_TEXTURE_2D);
    		glDisable(GL_LIGHTING);

    		glBegin(GL_POINTS);
    		glColor3f(1.f,0.f,0.f);
      	glVertex3f(0, 0, 0); // optical center
      	glColor3f(0.f,0.f,1.f);
      	glVertex3f(0, 0, normalized_focal); // image center
   	    glEnd();

   	    // compute image corners coordinated with normalized focal (f=normalized_focal)
   	    int w = m_doc._map_imageSize.find(i_cam)->second.first;
   	    int h = m_doc._map_imageSize.find(i_cam)->second.second;

   	    double focal = camera_i._K(0,0);
   	    // use principal point to adjust image center
   	    Vec2 pp(camera._K(0,2) , camera._K(1,2));

   	    Vec3 c1(    -pp[0]/focal * normalized_focal, (-pp[1]+h)/focal * normalized_focal, normalized_focal);
   	    Vec3 c2((-pp[0]+w)/focal * normalized_focal, (-pp[1]+h)/focal * normalized_focal, normalized_focal);
   	    Vec3 c3((-pp[0]+w)/focal * normalized_focal,     -pp[1]/focal * normalized_focal, normalized_focal);
   	    Vec3 c4(    -pp[0]/focal * normalized_focal,     -pp[1]/focal * normalized_focal, normalized_focal);

   	    // 2. Draw thumbnail
        if (i_cam == current_cam)
        {
          glEnable(GL_TEXTURE_2D);
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

          glBindTexture(GL_TEXTURE_2D, m_image_vector[i_cam].texture);

          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          glEnable(GL_BLEND);
          glDisable(GL_DEPTH_TEST);

          if (i_cam == current_cam) {
            glColor4f(0.5f,0.5f,0.5f, 0.7f);
          } else {
            glColor4f(0.5f,0.5f,0.5f, 0.5f);
          }

          glBegin(GL_QUADS);
          glTexCoord2d(0.0,1.0);    glVertex3d(c1[0], c1[1], c1[2]);
          glTexCoord2d(1.0,1.0);    glVertex3d(c2[0], c2[1], c2[2]);
          glTexCoord2d(1.0,0.0);    glVertex3d(c3[0], c3[1], c3[2]);
          glTexCoord2d(0.0,0.0);    glVertex3d(c4[0], c4[1], c4[2]);
          glEnd();

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

   	   // 3. Draw camera cone
   	    if (i_cam == current_cam) {
   	    	glColor3f(1.f,1.f,0.f);
   	    } else {
   	    	glColor3f(1.f,0.f,0.f);
   	    }
   	    glBegin(GL_LINES);
   	    glVertex3d(0.0,0.0,0.0); glVertex3d(c1[0], c1[1], c1[2]);
   	    glVertex3d(0.0,0.0,0.0); glVertex3d(c2[0], c2[1], c2[2]);
   	    glVertex3d(0.0,0.0,0.0); glVertex3d(c3[0], c3[1], c3[2]);
   	    glVertex3d(0.0,0.0,0.0); glVertex3d(c4[0], c4[1], c4[2]);
   	    glVertex3d(c1[0], c1[1], c1[2]); glVertex3d(c2[0], c2[1], c2[2]);
   	    glVertex3d(c2[0], c2[1], c2[2]); glVertex3d(c3[0], c3[1], c3[2]);
   	    glVertex3d(c3[0], c3[1], c3[2]); glVertex3d(c4[0], c4[1], c4[2]);
   	    glVertex3d(c4[0], c4[1], c4[2]); glVertex3d(c1[0], c1[1], c1[2]);
   	    glEnd();

   	    glPopMatrix(); // go back to current camera frame
   	}

    glPopMatrix(); // go back to (document +offset) frame
    glPopMatrix(); // go back to identity
  }
}
Example #18
0
void softPath(void)
{

    glViewport(winWidth/2, 0, winWidth/2, winHeight);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();



	gluPerspective(60, (GLfloat)(winWidth*0.5)/winHeight, 0.1, 25); //(60, (GLfloat)(winWidth*0.5)/winHeight, 0.1, 25)
	glGetDoublev(GL_PROJECTION_MATRIX, DEBUG_M);


    glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	gluLookAt(1, 1, 4, 0, 0, 0, 0, 1, 0);//1, 1, 4, 0, 1, 0, 0, 1, 0
	glGetDoublev(GL_MODELVIEW_MATRIX, DEBUG_M);



    glPushMatrix();
		glRotated(double(TICK), 0, 1, 0);
		glRotated(double(TICK)*0.1, 0, 0, 1);
		glTranslatef(LIGHTP, LIGHTP, 0);
		glutSolidSphere(0.05, 32, 32);
        glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
	glPopMatrix();

	glPushMatrix();
		//multiple trackball matrix
		glMultMatrixd(TRACKM);

		glScaled(MODELSCALE, MODELSCALE, MODELSCALE);
		glColor3f(1.0, 1.0, 1.0); //(0.7, 1.0, 1.0)
        swglmDraw(MODEL);//自造
		//glmDraw(MODEL, GLM_SMOOTH);//GLM_FLAT

		//glutSolidSphere(1, 20, 20);
	glPopMatrix();


	/*---------------------------------------*/
{/*
    //Do not change, setting a basic transformation
	glViewport(0, 0, winWidth, winHeight);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
	//glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
	glOrtho(0, winWidth, 0, winHeight, -2.0, 2.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//glColor3f(1, 0, 0);
	//OpenglLine(winWidth/2, 0, 0, winWidth, winHeight, 0);


	//
	//replace the opengl function in openglPath() to softgl
    //

	swClearZbuffer();



	//view transform
	swViewport(winWidth/2, 0, winWidth/2, winHeight);

    swMatrixMode(GL_PROJECTION);
    swLoadIdentity();

	//swOrtho(-2.0, 2.0, -2.0, 2.0, -3.0, 3.0);
	//swFrustum(-2.0, 2.0, -2.0, 2.0, -3.0, 3.0);
	swuPerspective(60, (GLfloat)(winWidth*0.5)/winHeight, 0.1, 25);

    swMatrixMode(GL_MODELVIEW);
	swLoadIdentity();
	swuLookAt(1, 1, 4, 0, 1, 0, 0, 1, 0);

    swPushMatrix();
		swRotated(double(TICK), 0, 1, 0);
		swRotated(double(TICK)*0.1, 0, 0, 1);
		swTranslated(LIGHTP, LIGHTP, 0);
		//swutSolidSphere(0.05, 32, 32);
        swLightfv(GL_LIGHT0, GL_POSITION, lightPos);
	swPopMatrix();


	//world coordinate
	glColor3f(1, 0, 0);
	SwglLine(0, 0, 0, 3, 0, 0);
	glColor3f(0, 1, 0);
	SwglLine(0, 0, 0, 0, 3, 0);
	glColor3f(0, 0, 1);
	SwglLine(0, 0, 0, 0, 0, 3);

	swPushMatrix();
		//multiple trackball matrix
		swMultMatrixd(TRACKM);

		swScaled(MODELSCALE, MODELSCALE, MODELSCALE);
		glColor3f(0.7, 1.0, 1.0);

		swglmDraw(MODEL);

	swPopMatrix();
*/
/*
	swPushMatrix();
		swTranslated(0, 2, 0);
		swMultMatrixd(TRACKM);

		SwglTri(-1, 0, 0,
				1, 0, 0,
				0, 1, 0,
				0, 0, 1,
				0, 0, 1,
				0, 0, 1,
				1, 0, 0,
				0, 1, 0,
				0, 0, 1);
	swPopMatrix();
*/
}
}
Example #19
0
void
world_display(void)
{
    GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };
    double length;
    float l[3];
    
    l[0] = lookat[3].value - lookat[0].value; 
    l[1] = lookat[4].value - lookat[1].value; 
    l[2] = lookat[5].value - lookat[2].value;
    length = normalize(l);
    
    invert(modelview, inverse);
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    if (world_draw) {
        glEnable(GL_LIGHTING);
        glPushMatrix();
        glMultMatrixd(inverse);
        glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
        glPopMatrix();
        drawmodel();
        glDisable(GL_LIGHTING);
    }
    
    glPushMatrix();
    
    glMultMatrixd(inverse);
    
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
    
    /* draw the axis and eye vector */
    glPushMatrix();
    glColor3ub(0, 0, 255);
    glBegin(GL_LINE_STRIP);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, -1.0*length);
    glVertex3f(0.1, 0.0, -0.9*length);
    glVertex3f(-0.1, 0.0, -0.9*length);
    glVertex3f(0.0, 0.0, -1.0*length);
    glVertex3f(0.0, 0.1, -0.9*length);
    glVertex3f(0.0, -0.1, -0.9*length);
    glVertex3f(0.0, 0.0, -1.0*length);
    glEnd();
    glColor3ub(255, 255, 0);
    glRasterPos3f(0.0, 0.0, -1.1*length);
    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'e');
    glColor3ub(255, 0, 0);
    glScalef(0.4, 0.4, 0.4);
    drawaxes();
    glPopMatrix();
    
    invert(projection, inverse);
    glMultMatrixd(inverse);
    
    /* draw the viewing frustum */
    glColor3f(0.2, 0.2, 0.2);
    glBegin(GL_QUADS);
    glVertex3i(1, 1, 1);
    glVertex3i(-1, 1, 1);
    glVertex3i(-1, -1, 1);
    glVertex3i(1, -1, 1);
    glEnd();
    
    glColor3ub(128, 196, 128);
    glBegin(GL_LINES);
    glVertex3i(1, 1, -1);
    glVertex3i(1, 1, 1);
    glVertex3i(-1, 1, -1);
    glVertex3i(-1, 1, 1);
    glVertex3i(-1, -1, -1);
    glVertex3i(-1, -1, 1);
    glVertex3i(1, -1, -1);
    glVertex3i(1, -1, 1);
    glEnd();
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(0.2, 0.2, 0.4, 0.5);
    glBegin(GL_QUADS);
    glVertex3i(1, 1, -1);
    glVertex3i(-1, 1, -1);
    glVertex3i(-1, -1, -1);
    glVertex3i(1, -1, -1);
    glEnd();
    glDisable(GL_BLEND);
    
    glPopMatrix();
    glutSwapBuffers();
}
Example #20
0
void render(void)
{
static GLint iFrames = 0;
static GLfloat fps = 0.0f, DeltaT;
static char cBuffer[64];
struct timeval tv;
GLuint model_id;

	// Update timer
	gettimeofday(&tv, NULL);
	etime = (double)tv.tv_sec + tv.tv_usec / 1000000.0f;

	dt = etime - t0;
	t0 = etime;

	/*
	 * Make the shadow pass
	 *
	 */

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, FBO );

	glPushMatrix();

		//Compute light position
		sinE = sinf(eLit);
		cosE = cosf(eLit);
		sinA = sinf(aLit);
		cosA = cosf(aLit);

		lightPos[0] = lightRadius * cosE * sinA;
		lightPos[1] = lightRadius * sinE;
		lightPos[2] = lightRadius * cosE * cosA;
		lightPos[3] = 1.0f;

		//Set light position
		glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

		//Set up camera to light location
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective( 70.0f, 1.0f, 75.0f, 350.0f );
		glGetDoublev(GL_PROJECTION_MATRIX, lightProjection );
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt( lightPos[0], lightPos[1], lightPos[2],
			0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f );
		glGetDoublev(GL_MODELVIEW_MATRIX, lightModelview );
		glViewport( 0, 0, shadow_sz, shadow_sz );

		glClear(GL_DEPTH_BUFFER_BIT);

		glEnable(GL_POLYGON_OFFSET_FILL);
		glShadeModel(GL_FLAT);

		//Rotate scene, if required
		glRotatef(xRot, 1.0f, 0.0f, 0.0f);
		glRotatef(yRot, 0.0f, 1.0f, 0.0f);

		//Disable shaders
		glUseProgramObjectARB(0);
		glDisable(GL_VERTEX_PROGRAM_ARB);
		glDisable(GL_FRAGMENT_PROGRAM_ARB);

		// Draw dynamic objects
		for (model_id = 0; model_id < NUM_MODELS; model_id++ )
		{
			//Update the kinematic's state
			UpdateMD2(md2_model[model_id], dt);
	
			//Animate the MD2 models
			AnimateMD2(md2_model[model_id], dt);
			
			//Draw the geometry
			glPushMatrix();
				glTranslatef(	md2_model[model_id]->position.x,
						md2_model[model_id]->position.y,
						md2_model[model_id]->position.z );
				glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f );
				DrawMD2(md2_model[model_id]);
			glPopMatrix();
		}

	glPopMatrix();

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );

	/*
	 * And now the normal pass
	 *
	 */

	//Back to normal settings
	glDisable(GL_POLYGON_OFFSET_FILL);
	glShadeModel(GL_SMOOTH);
	change_size( width, height );

	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();

		//Set up camera location and parameters
		setup_camera((float)dt);

		//Retrieve modelview matrix and invert it
		glGetDoublev(GL_MODELVIEW_MATRIX, cameraModelview );
		FastInvert4( cameraModelview, cameraModelviewInverse );

		//Set up depth texture
		glActiveTexture(GL_TEXTURE2);
		glBindTexture(GL_TEXTURE_2D, shadow_tx);

		//Set up texture matrix for shadow map projection
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		glTranslatef(0.5f, 0.5f, 0.5f);
		glScalef(0.5f, 0.5f, 0.5f);
		glMultMatrixd(lightProjection);
		glMultMatrixd(lightModelview);
		glMultMatrixd(cameraModelviewInverse);
		glMatrixMode(GL_MODELVIEW);

		//Rotate scene
		glRotatef(xRot, 1.0f, 0.0f, 0.0f);
		glRotatef(yRot, 0.0f, 1.0f, 0.0f);

		//Re-enable shaders
		glEnable(GL_VERTEX_PROGRAM_ARB);
		glEnable(GL_FRAGMENT_PROGRAM_ARB);

		if (GLSLshader)
			glUseProgramObjectARB(progObj);
		else
			glUseProgramObjectARB(0);

		//Floor

		//Color
		glColor3f(0.64f, 0.63f, 0.65f);

		//Set textures
		glActiveTexture(GL_TEXTURE0);	//Diffuse map
		glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-2]);

		glActiveTexture(GL_TEXTURE1);	//Normal map
		glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-1]);

		//Set Tangent vector
		glVertexAttrib3fv( tangent, floorT );

		//Set Binormal vector
		glVertexAttrib3fv( binormal, floorB );

		//Set Normal vector
		glNormal3fv( floorN );

		//Call Display List to draw
		glCallList(FList);

		// Draw dynamic objects
		for (model_id = 0; model_id < NUM_MODELS; model_id++ )
		{
			//Set color
			glColor3f(	md2_model[model_id]->color.x,
					md2_model[model_id]->color.y,
					md2_model[model_id]->color.z );
	
			//Set texture
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id]);
			glActiveTexture(GL_TEXTURE1);
			glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id+1]);
	
			//Draw the geometry
			glPushMatrix();
				glTranslatef(	md2_model[model_id]->position.x,
						md2_model[model_id]->position.y,
						md2_model[model_id]->position.z );
				glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f );
				DrawMD2(md2_model[model_id]);
			glPopMatrix();
		}

	glPopMatrix();

	iFrames++;
	DeltaT = (GLfloat)(etime-t1);
	if( DeltaT >= Timed )
	{
		fps = (GLfloat)(iFrames)/DeltaT;
		fps_count++;
		fps_mean = ((fps_count - 1.0f) * fps_mean + fps ) / fps_count;

		iFrames = 0;
		t1 = etime;

		sprintf(cBuffer,"FPS: %.1f Mean FPS: %.1f Poly Scale: %.1f Bias: %.1f", fps, fps_mean, scalePoly, biasPoly);
	}
	if (print_fps)
	{
		if (windowpos)
		{
			glColor3f(1.0f, 1.0f, 1.0f);
			glPushAttrib(GL_LIST_BIT);
				glListBase(fps_font - ' ');
				glWindowPos2i(0,2);
				glCallLists(strlen(cBuffer), GL_UNSIGNED_BYTE, cBuffer);
			glPopAttrib();
		}
		if( iFrames == 0 )
			printf("FPS: %.1f Mean FPS: %.1f\n", fps, fps_mean);
	}
	lCam = 0.0f;
	vCam = 0.0f;
	dCam = 0.0f;
}
Example #21
0
void Planet::DrawAtmosphere(const vector3d &camPos)
{
	Color col;
	double density;
	GetSBody()->GetAtmosphereFlavor(&col, &density);
	
	const double rad1 = 0.999;
	const double rad2 = 1.05;

	glPushMatrix();

	// face the camera dammit
	vector3d zaxis = (-camPos).Normalized();
	vector3d xaxis = vector3d(0,1,0).Cross(zaxis).Normalized();
	vector3d yaxis = zaxis.Cross(xaxis);
	matrix4x4d rot = matrix4x4d::MakeInvRotMatrix(xaxis, yaxis, zaxis);
	glMultMatrixd(&rot[0]);

	matrix4x4f invViewRot;
	glGetFloatv(GL_MODELVIEW_MATRIX, &invViewRot[0]);
	invViewRot.ClearToRotOnly();
	invViewRot = invViewRot.InverseOf();

	const int numLights = Pi::worldView->GetNumLights();
	assert(numLights < 4);
	vector3f lightDir[4];
	float lightCol[4][4];
	// only 
	for (int i=0; i<numLights; i++) {
		float temp[4];
		glGetLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lightCol[i]);
		glGetLightfv(GL_LIGHT0 + i, GL_POSITION, temp);
		lightDir[i] = (invViewRot * vector3f(temp[0], temp[1], temp[2])).Normalized();
	}

	const double angStep = M_PI/32;
	// find angle player -> centre -> tangent point
	// tangent is from player to surface of sphere
	float tanAng = float(acos(rad1 / camPos.Length()));

	// then we can put the f*****g atmosphere on the horizon
	vector3d r1(0.0, 0.0, rad1);
	vector3d r2(0.0, 0.0, rad2);
	rot = matrix4x4d::RotateYMatrix(tanAng);
	r1 = rot * r1;
	r2 = rot * r2;

	rot = matrix4x4d::RotateZMatrix(angStep);

	glDisable(GL_LIGHTING);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);	
	glEnable(GL_BLEND);
	glDisable(GL_CULL_FACE);
	glBegin(GL_TRIANGLE_STRIP);
	for (float ang=0; ang<2*M_PI; ang+=float(angStep)) {
		vector3d norm = r1.Normalized();
		glNormal3dv(&norm.x);
		float _col[4] = { 0,0,0,0 };
		for (int lnum=0; lnum<numLights; lnum++) {
			const float dot = norm.x*lightDir[lnum].x + norm.y*lightDir[lnum].y + norm.z*lightDir[lnum].z;
			_col[0] += dot*lightCol[lnum][0];
			_col[1] += dot*lightCol[lnum][1];
			_col[2] += dot*lightCol[lnum][2];
		}
		for (int i=0; i<3; i++) _col[i] = _col[i] * col[i];
		_col[3] = col[3];
		glColor4fv(_col);
		glVertex3dv(&r1.x);
		glColor4f(0,0,0,0);
		glVertex3dv(&r2.x);
		r1 = rot * r1;
		r2 = rot * r2;
	}
	
	glEnd();
	glEnable(GL_CULL_FACE);
	glDisable(GL_BLEND);
	glEnable(GL_LIGHTING);
	glPopMatrix();
}
void RAS_OpenGLRasterizer::applyTransform(double* oglmatrix,int objectdrawmode )
{
	/* FIXME:
	blender: intern/moto/include/MT_Vector3.inl:42: MT_Vector3 operator/(const
	MT_Vector3&, double): Assertion `!MT_fuzzyZero(s)' failed.

	Program received signal SIGABRT, Aborted.
	[Switching to Thread 16384 (LWP 1519)]
	0x40477571 in kill () from /lib/libc.so.6
	(gdb) bt
	#7  0x08334368 in MT_Vector3::normalized() const ()
	#8  0x0833e6ec in RAS_OpenGLRasterizer::applyTransform(RAS_IRasterizer*, double*, int) ()
	*/

	if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
		objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
	{
		// rotate the billboard/halo
		//page 360/361 3D Game Engine Design, David Eberly for a discussion
		// on screen aligned and axis aligned billboards
		// assumed is that the preprocessor transformed all billboard polygons
		// so that their normal points into the positive x direction (1.0, 0.0, 0.0)
		// when new parenting for objects is done, this rotation
		// will be moved into the object

		MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
		MT_Point3 campos = GetCameraPosition();
		MT_Vector3 dir = (campos - objpos).safe_normalized();
		MT_Vector3 up(0,0,1.0);

		KX_GameObject* gameobj = (KX_GameObject*)m_clientobject;
		// get scaling of halo object
		MT_Vector3  size = gameobj->GetSGNode()->GetWorldScaling();

		bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
		if (screenaligned)
		{
			up = (up - up.dot(dir) * dir).safe_normalized();
		} else
		{
			dir = (dir - up.dot(dir)*up).safe_normalized();
		}

		MT_Vector3 left = dir.normalized();
		dir = (up.cross(left)).normalized();

		// we have calculated the row vectors, now we keep
		// local scaling into account:

		left *= size[0];
		dir  *= size[1];
		up   *= size[2];

		double maat[16] = {left[0], left[1], left[2], 0,
		                   dir[0],  dir[1],  dir[2],  0,
		                   up[0],   up[1],   up[2],   0,
		                   0,       0,       0,       1};

		glTranslated(objpos[0],objpos[1],objpos[2]);
		glMultMatrixd(maat);

	}
	else {
		if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
		{
			// shadow must be cast to the ground, physics system needed here!
			MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
			KX_GameObject *gameobj = (KX_GameObject*)m_clientobject;
			MT_Vector3 direction = MT_Vector3(0,0,-1);

			direction.normalize();
			direction *= 100000;

			MT_Point3 topoint = frompoint + direction;

			KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
			PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
			PHY_IPhysicsController* physics_controller = gameobj->GetPhysicsController();

			KX_GameObject *parent = gameobj->GetParent();
			if (!physics_controller && parent)
				physics_controller = parent->GetPhysicsController();
			if (parent)
				parent->Release();

			KX_RayCast::Callback<RAS_OpenGLRasterizer> callback(this, physics_controller, oglmatrix);
			if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
			{
				// couldn't find something to cast the shadow on...
				glMultMatrixd(oglmatrix);
			}
			else
			{ // we found the "ground", but the cast matrix doesn't take
			  // scaling in consideration, so we must apply the object scale
				MT_Vector3  size = gameobj->GetSGNode()->GetLocalScale();
				glScalef(size[0], size[1], size[2]);
			}
		} else
		{

			// 'normal' object
			glMultMatrixd(oglmatrix);
		}
	}
}
//--------------------------------------------------------------
void ofxBulletCapsule::draw() {
	if(!_bCreated || _rigidBody == NULL) {
		ofLog(OF_LOG_WARNING, "ofxBulletCapsule :: draw : must call create() first and add() after");
		return;
	}
	
	btScalar	m[16];
	ofGetOpenGLMatrixFromRigidBody( _rigidBody, m );
	glPushMatrix();
#ifdef BT_USE_DOUBLE_PRECISION
	glMultMatrixd(m);
#else
	glMultMatrixf( m );
#endif
	
	if(hull == NULL) {
		hull = new btShapeHull((btConvexShape*)_rigidBody->getCollisionShape());
	
		btScalar margin = _rigidBody->getCollisionShape()->getMargin();
		hull->buildHull(margin);
	}
	
	if (hull->numTriangles () > 0) {
		int index = 0;
		const unsigned int* idx = hull->getIndexPointer();
		const btVector3* vtx = hull->getVertexPointer();
		
		glBegin (GL_TRIANGLES);
		
		for (int i = 0; i < hull->numTriangles (); i++) {
			int i1 = index++;
			int i2 = index++;
			int i3 = index++;
			btAssert(i1 < hull->numIndices () &&
					 i2 < hull->numIndices () &&
					 i3 < hull->numIndices ());
			
			int index1 = idx[i1];
			int index2 = idx[i2];
			int index3 = idx[i3];
			btAssert(index1 < hull->numVertices () &&
					 index2 < hull->numVertices () &&
					 index3 < hull->numVertices ());
			
			btVector3 v1 = vtx[index1];
			btVector3 v2 = vtx[index2];
			btVector3 v3 = vtx[index3];
			btVector3 normal = (v3-v1).cross(v2-v1);
			normal.normalize();
			glNormal3f(normal.getX(),normal.getY(),normal.getZ());
			glVertex3f (v1.x(), v1.y(), v1.z());
			glVertex3f (v2.x(), v2.y(), v2.z());
			glVertex3f (v3.x(), v3.y(), v3.z());
			
		}
		glEnd ();
		
	}
	
	glPopMatrix();
}
Example #24
0
/*
 *  Draw solid airplane
 *    at (x,y,z)
 *    nose towards (dx,dy,dz)
 *    up towards (ux,uy,uz)
 */
static void SolidPlane(double x,double y,double z,
                       double dx,double dy,double dz,
                       double ux,double uy, double uz)
{
   // Dimenslookations used to size airplane
   const double wid=0.05;
   const double nose=+0.50;
   const double cone= 0.20;
   const double wing= 0.00;
   const double strk=-0.20;
   const double tail=-0.50;
   //  Unit vector in direction of flght
   double D0 = sqrt(dx*dx+dy*dy+dz*dz);
   double X0 = dx/D0;
   double Y0 = dy/D0;
   double Z0 = dz/D0;
   //  Unit vector in "up" direction
   double D1 = sqrt(ux*ux+uy*uy+uz*uz);
   double X1 = ux/D1;
   double Y1 = uy/D1;
   double Z1 = uz/D1;
   //  Cross product gives the third vector
   double X2 = Y0*Z1-Y1*Z0;
   double Y2 = Z0*X1-Z1*X0;
   double Z2 = X0*Y1-X1*Y0;
   //  Rotation matrix
   double mat[16];
   mat[0] = X0;   mat[4] = X1;   mat[ 8] = X2;   mat[12] = 0;
   mat[1] = Y0;   mat[5] = Y1;   mat[ 9] = Y2;   mat[13] = 0;
   mat[2] = Z0;   mat[6] = Z1;   mat[10] = Z2;   mat[14] = 0;
   mat[3] =  0;   mat[7] =  0;   mat[11] =  0;   mat[15] = 1;

   //  Save current transforms
   glPushMatrix();
   //  Offset, scale and rotate
   glTranslated(x,y,z);
   glMultMatrixd(mat);
   //  Nose (4 sided)
   glColor3f(0,0,1);
   glBegin(GL_TRIANGLES);
   glVertex3d(nose, 0.0, 0.0);
   glVertex3d(cone, wid, wid);
   glVertex3d(cone,-wid, wid);

   glVertex3d(nose, 0.0, 0.0);
   glVertex3d(cone, wid,-wid);
   glVertex3d(cone,-wid,-wid);

   glVertex3d(nose, 0.0, 0.0);
   glVertex3d(cone, wid, wid);
   glVertex3d(cone, wid,-wid);

   glVertex3d(nose, 0.0, 0.0);
   glVertex3d(cone,-wid, wid);
   glVertex3d(cone,-wid,-wid);
   glEnd();
   //  Fuselage (square tube)
   glBegin(GL_QUADS);
   glVertex3d(cone, wid, wid);
   glVertex3d(cone,-wid, wid);
   glVertex3d(tail,-wid, wid);
   glVertex3d(tail, wid, wid);

   glVertex3d(cone, wid,-wid);
   glVertex3d(cone,-wid,-wid);
   glVertex3d(tail,-wid,-wid);
   glVertex3d(tail, wid,-wid);

   glVertex3d(cone, wid, wid);
   glVertex3d(cone, wid,-wid);
   glVertex3d(tail, wid,-wid);
   glVertex3d(tail, wid, wid);

   glVertex3d(cone,-wid, wid);
   glVertex3d(cone,-wid,-wid);
   glVertex3d(tail,-wid,-wid);
   glVertex3d(tail,-wid, wid);

   glVertex3d(tail,-wid, wid);
   glVertex3d(tail, wid, wid);
   glVertex3d(tail, wid,-wid);
   glVertex3d(tail,-wid,-wid);
   glEnd();
   //  Wings (plane triangles)
   glColor3f(1,1,0);
   glBegin(GL_TRIANGLES);
   glVertex3d(wing, 0.0, wid);
   glVertex3d(tail, 0.0, wid);
   glVertex3d(tail, 0.0, 0.5);

   glVertex3d(wing, 0.0,-wid);
   glVertex3d(tail, 0.0,-wid);
   glVertex3d(tail, 0.0,-0.5);
   glEnd();
   //  Vertical tail (plane triangle)
   glColor3f(1,0,0);
   glBegin(GL_POLYGON);
   glVertex3d(strk, 0.0, 0.0);
   glVertex3d(tail, 0.3, 0.0);
   glVertex3d(tail, 0.0, 0.0);
   glEnd();
   //  Undo transformations
   glPopMatrix();
}
Example #25
0
void Scarry::drawtra(wardraw_t *wd){
	st::drawtra(wd);
	Scarry *p = this;
	Scarry *pt = this;
	Mat4d mat;
	Vec3d pa, pb, pa0(.01, 0, 0), pb0(-.01, 0, 0);
	double scale;

/*	if(scarry_cull(pt, wd))
		return;*/

	if(wd->vw->gc->cullFrustum(pos, getHitRadius()))
		return;

	scale = fabs(wd->vw->gc->scale(this->pos));

	transform(mat);

	const double blastscale = .04;
	drawCapitalBlast(wd, Vec3d(0, 0, .55), blastscale);
	drawCapitalBlast(wd, Vec3d(.08, .08, .55), blastscale);
	drawCapitalBlast(wd, Vec3d(-.08, .08, .55), blastscale);
	drawCapitalBlast(wd, Vec3d(-.08, -.08, .55), blastscale);
	drawCapitalBlast(wd, Vec3d(.08, -.08, .55), blastscale);

	pa = pt->rot.trans(pa0);
	pa += pt->pos;
	pb = pt->rot.trans(pb0);
	pb += pt->pos;
	glColor4ub(255,255,9,255);
	glBegin(GL_LINES);
	glVertex3dv(pa);
	glVertex3dv(pb);
	glEnd();

	{
		int i;
		static const avec3_t lights[] = {
			{0, 520 * SCARRY_SCALE, 220 * SCARRY_SCALE},
			{0, -520 * SCARRY_SCALE, 220 * SCARRY_SCALE},
			{140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE},
			{-140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE},
			{140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE},
			{-140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE},
			{100 * SCARRY_SCALE, -360 * SCARRY_SCALE, -600 * SCARRY_SCALE},
			{100 * SCARRY_SCALE,  360 * SCARRY_SCALE, -600 * SCARRY_SCALE},
			{ 280 * SCARRY_SCALE,   20 * SCARRY_SCALE, 520 * SCARRY_SCALE},
			{ 280 * SCARRY_SCALE,  -20 * SCARRY_SCALE, 520 * SCARRY_SCALE},
			{-280 * SCARRY_SCALE,   20 * SCARRY_SCALE, 520 * SCARRY_SCALE},
			{-280 * SCARRY_SCALE,  -20 * SCARRY_SCALE, 520 * SCARRY_SCALE},
			{-280 * SCARRY_SCALE,   20 * SCARRY_SCALE, -300 * SCARRY_SCALE},
			{-280 * SCARRY_SCALE,  -20 * SCARRY_SCALE, -300 * SCARRY_SCALE},
			{ 280 * SCARRY_SCALE,   20 * SCARRY_SCALE, -480 * SCARRY_SCALE},
			{ 280 * SCARRY_SCALE,  -20 * SCARRY_SCALE, -480 * SCARRY_SCALE},
		};
		avec3_t pos;
		double rad = .01;
		double t;
		GLubyte col[4] = {255, 31, 31, 255};
		random_sequence rs;
		init_rseq(&rs, (unsigned long)this);

		/* color calculation of static navlights */
		t = fmod(wd->vw->viewtime + drseq(&rs) * 2., 2.);
		if(t < 1.){
			rad *= (t + 1.) / 2.;
			col[3] *= t;
		}
		else{
			rad *= (2. - t + 1.) / 2.;
			col[3] *= 2. - t;
		}
		for(i = 0 ; i < numof(lights); i++){
			mat4vp3(pos, mat, lights[i]);
			gldSpriteGlow(pos, rad, col, wd->vw->irot);
		}

		/* runway lights */
		if(1 < scale * .01){
			col[0] = 0;
			col[1] = 191;
			col[2] = 255;
			for(i = 0 ; i <= 10; i++){
				avec3_t pos0;
				pos0[0] = -160 * SCARRY_SCALE;
				pos0[1] = 20 * SCARRY_SCALE + .0025;
				pos0[2] = (i * -460 + (10 - i) * -960) * SCARRY_SCALE / 10;
				rad = .005 * (1. - fmod(i / 10. + t / 2., 1.));
				col[3] = 255/*rad * 255 / .01*/;
				mat4vp3(pos, mat, pos0);
				gldSpriteGlow(pos, rad, col, wd->vw->irot);
				pos0[0] = -40 * SCARRY_SCALE;
				mat4vp3(pos, mat, pos0);
				gldSpriteGlow(pos, rad, col, wd->vw->irot);
				pos0[1] = -20 * SCARRY_SCALE - .0025;
				mat4vp3(pos, mat, pos0);
				gldSpriteGlow(pos, rad, col, wd->vw->irot);
				pos0[0] = -160 * SCARRY_SCALE;
				mat4vp3(pos, mat, pos0);
				gldSpriteGlow(pos, rad, col, wd->vw->irot);
			}
		}

/*		for(i = 0; i < numof(p->turrets); i++)
			mturret_drawtra(&p->turrets[i], pt, wd);*/
	}

	static int init = 0;
	static suftex_t *pst;
	static suf_t *sufbase = NULL;
	if(init == 0) do{
		init = 1;
		sufbase = CallLoadSUF("models/spacecarrier.bin");
	} while(0);
	if(sufbase){
		static const double normal[3] = {0., 1., 0.};
		double scale = SCARRY_SCALE;
		static const GLdouble rotaxis[16] = {
			-1,0,0,0,
			0,1,0,0,
			0,0,-1,0,
			0,0,0,1,
		};
		Mat4d mat;

		glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT);
		glEnable(GL_CULL_FACE);
		glPushMatrix();
		transform(mat);
		glMultMatrixd(mat);

		extern GLuint screentex;
		glBindTexture(GL_TEXTURE_2D, screentex);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		glColor4f(1.,1.,1.,1.);
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);

		Mat4d modelview, proj;
		glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
		glGetDoublev(GL_PROJECTION_MATRIX, proj);
		Mat4d trans = proj * modelview;
		texture((glPushMatrix(),
			glScaled(1./2., 1./2., 1.),
			glTranslated(1, 1, 0),
			glMultMatrixd(trans)
		));
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(.9,0,0,0));
		glEnable(GL_TEXTURE_GEN_S);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,.9,0,0));
		glEnable(GL_TEXTURE_GEN_T);
		glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGendv(GL_R, GL_EYE_PLANE, Vec4d(0,0,.9,0));
		glEnable(GL_TEXTURE_GEN_R);
		glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1));
		glEnable(GL_TEXTURE_GEN_Q);

		glPushMatrix();
		glScaled(-scale, scale, -scale);
		DrawSUF(sufbase, 0, NULL);
		glPopMatrix();

		texture((glPopMatrix()));
		glPopMatrix();
		glPopAttrib();
	}
}
Example #26
0
void CEdge::glCommands(bool select, bool marked, bool no_color){
	if(!no_color){
		wxGetApp().glColorEnsuringContrast(HeeksColor(0, 0, 0));
	}

	if(m_owner && m_owner->m_owner && m_owner->m_owner->GetType() == SolidType)
	{
		// triangulate a face on the edge first
		if(this->m_faces.size() > 0)
		{
			TopLoc_Location fL;
			Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(m_faces.front()->Face(),fL);

			if(!facing.IsNull())
			{
				// Get polygon
				Handle_Poly_PolygonOnTriangulation polygon = BRep_Tool::PolygonOnTriangulation(m_topods_edge, facing, fL);
				gp_Trsf tr = fL;
				double m[16];
				extract_transposed(tr, m);
				glPushMatrix();
				glMultMatrixd(m);

				if (!polygon.IsNull())
				{
					glBegin(GL_LINE_STRIP);
					const TColStd_Array1OfInteger& Nodes = polygon->Nodes();
					const TColgp_Array1OfPnt& FNodes = facing->Nodes();
					int nnn = polygon->NbNodes();
					for (int nn = 1; nn <= nnn; nn++)
					{
						gp_Pnt v = FNodes(Nodes(nn));
						glVertex3d(v.X(), v.Y(), v.Z());
					}
					glEnd();
				}

				glPopMatrix();
			}
		}
	}
	else
	{
		bool glwidth_done = false;
		GLfloat save_depth_range[2];
		if(m_owner == NULL || m_owner->m_owner == NULL || m_owner->m_owner->GetType() != WireType)
		{
			BRepTools::Clean(m_topods_edge);
			double pixels_per_mm = wxGetApp().GetPixelScale();
			BRepMesh_IncrementalMesh(m_topods_edge, 1/pixels_per_mm);
			if(marked){
				glGetFloatv(GL_DEPTH_RANGE, save_depth_range);
				glDepthRange(0, 0);
				glLineWidth(2);
				glwidth_done = true;
			}
		}

		TopLoc_Location L;
		Handle(Poly_Polygon3D) Polyg = BRep_Tool::Polygon3D(m_topods_edge, L);
		if (!Polyg.IsNull()) {
			const TColgp_Array1OfPnt& Points = Polyg->Nodes();
			Standard_Integer po;
			glBegin(GL_LINE_STRIP);
			for (po = Points.Lower(); po <= Points.Upper(); po++) {
				gp_Pnt p = (Points.Value(po)).Transformed(L);
				glVertex3d(p.X(), p.Y(), p.Z());
			}
			glEnd();
		}

		if(glwidth_done)
		{
			glLineWidth(1);
			glDepthRange(save_depth_range[0], save_depth_range[1]);
		}
	}
}
Example #27
0
   void VisualSceneOCCGeometry :: MouseDblClick (int px, int py)
   {
      int hits;

      // select surface triangle by mouse click

      GLuint selbuf[10000];
      glSelectBuffer (10000, selbuf);

      glRenderMode (GL_SELECT);

      GLint viewport[4];
      glGetIntegerv (GL_VIEWPORT, viewport);

      glMatrixMode (GL_PROJECTION);
      glPushMatrix();

      GLdouble projmat[16];
      glGetDoublev (GL_PROJECTION_MATRIX, projmat);

      glLoadIdentity();
      gluPickMatrix (px, viewport[3] - py, 1, 1, viewport);
      glMultMatrixd (projmat);

      glClearColor(backcolor, backcolor, backcolor, 1.0);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      glMatrixMode (GL_MODELVIEW);

      glPushMatrix();
      glMultMatrixf (transformationmat);

      glInitNames();
      glPushName (1);

      glPolygonOffset (1, 1);
      glEnable (GL_POLYGON_OFFSET_FILL);

      glDisable(GL_CLIP_PLANE0);

      // Philippose - 30/01/2009
      // Enable clipping planes for Selection mode in OCC Geometry
      if (vispar.clipenable)
      {
         Vec<3> n(clipplane[0], clipplane[1], clipplane[2]);
         double len = Abs(n);
         double mu = -clipplane[3] / (len*len);
         Point<3> p (mu * n);
         n /= len;
         Vec<3> t1 = n.GetNormal ();
         Vec<3> t2 = Cross (n, t1);

         double xi1mid = (center - p) * t1;
         double xi2mid = (center - p) * t2;

         glLoadName (0);
         glBegin (GL_QUADS);
         glVertex3dv (p + (xi1mid-rad) * t1 + (xi2mid-rad) * t2);
         glVertex3dv (p + (xi1mid+rad) * t1 + (xi2mid-rad) * t2);
         glVertex3dv (p + (xi1mid+rad) * t1 + (xi2mid+rad) * t2);
         glVertex3dv (p + (xi1mid-rad) * t1 + (xi2mid+rad) * t2);
         glEnd ();
      }

      glCallList (trilists.Get(1));

      glDisable (GL_POLYGON_OFFSET_FILL);

      glPopName();

      glMatrixMode (GL_PROJECTION);
      glPopMatrix();

      glMatrixMode (GL_MODELVIEW);
      glPopMatrix();

      glFlush();

      hits = glRenderMode (GL_RENDER);

      int minname = 0;
      GLuint mindepth = 0;

      // find clippingplane
      GLuint clipdepth = 0; // GLuint(-1);

      for (int i = 0; i < hits; i++)
      {
         int curname = selbuf[4*i+3];
         if (!curname) clipdepth = selbuf[4*i+1];
      }

      for (int i = 0; i < hits; i++)
      {
         int curname = selbuf[4*i+3];
         GLuint curdepth = selbuf[4*i+1];
         if (curname && (curdepth> clipdepth) &&
               (curdepth < mindepth || !minname))
         {
            mindepth = curdepth;
            minname = curname;
         }
      }

      occgeometry->LowLightAll();

      if (minname)
      {
         occgeometry->fvispar[minname-1].Highlight();

         if (vispar.occzoomtohighlightedentity)
         occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
         else
         occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
         cout << "Selected face: " << minname << endl;
      }
      else
      {
         occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
      }

      glDisable(GL_CLIP_PLANE0);

      SelectFaceInOCCDialogTree (minname);

      // Philippose - 30/01/2009
      // Set the currently selected face in the array
      // for local face mesh size definition
      occgeometry->SetSelectedFace(minname);

      //  selecttimestamp = NextTimeStamp();
   }
void drawCurMapPoint(const MapPoint* p, double range, double pointSize,
		bool drawCov) {
	//GLfloat LightAmbient[] = { 0.5f, 1.0f, 0.5f, 1.0f };
	GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
	GLfloat LightAmbientInAct[] = { 0.5f, 0.5f, 0.5f, 1.0f };
	GLfloat LightDiffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f };
	GLfloat LightPosition[] = { -range * 1.0f, -range * 1.0f, 0.0f, 1.0f };

	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbientInAct);
	glLightfv(GL_POSITION, GL_DIFFUSE, LightAmbientInAct);

	if( p->isFalse())
		return;
	
	glColor3f(0.2f, 0.8f, 0.2f);

	//for debug
	if (p->flag == FLAG_MAPPOINT_TEST4)
		glColor3f(1.0f, 0.0f, 0.0f);

//	glEnable(GL_LIGHTING);
//	glEnable(GL_LIGHT1);
//
//	glPushMatrix();
//	glTranslatef(p->x, p->y, p->z);
//	glutSolidSphere(0.1 * range * p->numVisCam, 12, 12);
//	glPopMatrix();
//
//	glDisable(GL_LIGHT1);
//	glDisable(GL_LIGHTING);


	if(p->isFalse())
		return;
	
	glPointSize(4.0 * pointSize);

	glBegin(GL_POINTS);
	glVertex3d(p->x, p->y, p->z);
	glEnd();

	if (drawCov && p->cov[0] > 0) {		
		glColor4f(0.2f, 0.8f, 0.2f, 0.2f);

//		//for debug
//		if (p->flag == FLAG_MAPPOINT_TEST4
//		)
//			glColor3f(1.0f, 0.0f, 0.0f);

		double evec[9];
		double eval[3];
		dgeevFor(3, p->cov, evec, eval);
		glPushMatrix();
		glTranslatef(p->x, p->y, p->z);
		double rotMat[16];
		memset(rotMat, 0, sizeof(double) * 16);
		memcpy(rotMat, evec, sizeof(double) * 3);
		memcpy(rotMat + 4, evec + 3, sizeof(double) * 3);
		memcpy(rotMat + 8, evec + 3, sizeof(double) * 3);
		rotMat[15] = 1;
		glMultMatrixd(rotMat);
		//assert(eval[0] > 0 && eval[1] > 0 && eval[2] > 0);
		glScaled(sqrt(eval[0]), sqrt(eval[1]), sqrt(eval[2]));
		glutSolidSphere(1.0, 12, 12);
		glPopMatrix();
	}
}
Example #29
0
//
// This function is called when the window needs redrawing.
//
static void Display(void)
{
	// Select correct buffer for this context.
	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
    
    arglPixelBufferDataUpload(gArglSettings, gARTImage);
    arglDispImage(gArglSettings);
	gARTImage = NULL; // Invalidate image data.
				
    // Set up 3D mode.
	glMatrixMode(GL_PROJECTION);
#ifdef ARDOUBLE_IS_FLOAT
	glLoadMatrixf(cameraLens);
#else
	glLoadMatrixd(cameraLens);
#endif
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
    glEnable(GL_DEPTH_TEST);

    // Set any initial per-frame GL state you require here.
    // --->
    
    // Lighting and geometry that moves with the camera should be added here.
    // (I.e. should be specified before camera pose transform.)
    // --->
    
    VirtualEnvironmentHandleARViewDrawPreCamera();
    
    if (cameraPoseValid) {
        
#ifdef ARDOUBLE_IS_FLOAT
        glMultMatrixf(cameraPose);
#else
        glMultMatrixd(cameraPose);
#endif
        
        // All lighting and geometry to be drawn in world coordinates goes here.
        // --->
        VirtualEnvironmentHandleARViewDrawPostCamera();
    }
    
    // Set up 2D mode.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, (GLdouble)gWindowW, 0, (GLdouble)gWindowH, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);

    // Add your own 2D overlays here.
    // --->
    
    VirtualEnvironmentHandleARViewDrawOverlay();

    //
    // Draw help text and mode.
    //
    if (gShowMode) {
        printMode();
    }
    if (gShowHelp) {
        if (gShowHelp == 1) {
            printHelpKeys();
        }
    }
	
	glutSwapBuffers();
}
Example #30
0
inline void glMatrixd::glMultMatrix() const
{
  glMultMatrixd(data);
}