Beispiel #1
0
// Spinning Cube!
inline void scene2(float scene_time)
{
  int i = scene_time / 25;

  tglClear(TGL_COLOR_BUFFER_BIT);

  float zoom = 0;
  if(scene_time > 5000)
    zoom = 0.5*sin((float)(i-20)/10.0);
    
  float rot_speed = 1.0;
  if(scene_time > 12000)
    rot_speed += (float)(scene_time - 12000) / 1500.0;

  tglMatrixMode(TGL_MODELVIEW);
  tglLoadIdentity();
  tglTranslatef(0, 0, -2.5+zoom);

  tglRotatef((float)(i % 360) * rot_speed, 0, 1, 0);
  tglRotatef((float)(i % 360) * rot_speed, 1, 1, 0);

  tglBegin(TGL_LINES);
  for(int p=0; p<8; ++p) {
    tglVertex3fv(cube[cubestrip1[p]]);
  }
  tglEnd();

  tglBegin(TGL_LINES);
  for(int p=0; p<8; ++p) {
    tglVertex3fv(cube[cubestrip2[p]]);
  }
  tglEnd();

  tglSwap();
}
Beispiel #2
0
// Zoom into the cube
inline void scene1(float scene_time)
{
  tglClear(TGL_COLOR_BUFFER_BIT);  

  float min_zoom = -10;
  float max_zoom = -2.5;
  float zoom = min_zoom + (max_zoom-min_zoom) * (float)scene_time/timeline[scene];

  tglMatrixMode(TGL_MODELVIEW);
  tglLoadIdentity();
  tglTranslatef(0, 0, zoom);

  tglBegin(TGL_LINES);
  for(int p=0; p<8; ++p) {
    tglVertex3fv(cube[cubestrip1[p]]);
  }
  tglEnd();

  tglBegin(TGL_LINES);
  for(int p=0; p<8; ++p) {
    tglVertex3fv(cube[cubestrip2[p]]);
  }
  tglEnd();

  tglSwap();
  
  delay(50);
}
Beispiel #3
0
void GfxTinyGL::drawHierachyNode(const ModelNode *node, int *x1, int *y1, int *x2, int *y2) {
	Graphics::Vector3d animPos = node->_pos + node->_animPos;
	float animPitch = node->_pitch + node->_animPitch;
	float animYaw = node->_yaw + node->_animYaw;
	float animRoll = node->_roll + node->_animRoll;
	translateViewpointStart(animPos, animPitch, animYaw, animRoll);
	if (node->_hierVisible) {
		tglPushMatrix();
		tglTranslatef(node->_pivot.x(), node->_pivot.y(), node->_pivot.z());

		if (!_currentShadowArray) {
			Sprite* sprite = node->_sprite;
			while (sprite) {
				sprite->draw();
				sprite = sprite->_next;
			}
		}

		if (node->_mesh && node->_meshVisible) {
			node->_mesh->draw(x1, y1, x2, y2);
		}

		tglMatrixMode(TGL_MODELVIEW);
		tglPopMatrix();

		if (node->_child) {
			node->_child->draw(x1, y1, x2, y2);
			tglMatrixMode(TGL_MODELVIEW);
		}
	}
	translateViewpointFinish();

	if (node->_sibling)
		node->_sibling->draw(x1, y1, x2, y2);
}
Beispiel #4
0
void GfxTinyGL::startActorDraw(Graphics::Vector3d pos, float scale, float yaw, float pitch, float roll) {
	tglEnable(TGL_TEXTURE_2D);
	tglMatrixMode(TGL_MODELVIEW);
	tglPushMatrix();
	if (_currentShadowArray) {
		// TODO find out why shadowMask at device in woods is null
		if (!_currentShadowArray->shadowMask) {
			_currentShadowArray->shadowMask = new byte[_screenWidth * _screenHeight];
			_currentShadowArray->shadowMaskSize = _screenWidth * _screenHeight;
		}
		assert(_currentShadowArray->shadowMask);
		//tglSetShadowColor(255, 255, 255);
		tglSetShadowColor(_shadowColorR, _shadowColorG, _shadowColorB);
		tglSetShadowMaskBuf(_currentShadowArray->shadowMask);
		SectorListType::iterator i = _currentShadowArray->planeList.begin();
		Sector *shadowSector = i->sector;
		tglShadowProjection(_currentShadowArray->pos, shadowSector->getVertices()[0], shadowSector->getNormal(), _currentShadowArray->dontNegate);
	}

	tglTranslatef(pos.x(), pos.y(), pos.z());
	tglScalef(scale, scale, scale);
	tglRotatef(yaw, 0, 0, 1);
	tglRotatef(pitch, 1, 0, 0);
	tglRotatef(roll, 0, 1, 0);
}
Beispiel #5
0
void GfxTinyGL::translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll) {
	tglPushMatrix();

	tglTranslatef(pos.x(), pos.y(), pos.z());
	tglRotatef(yaw, 0, 0, 1);
	tglRotatef(pitch, 1, 0, 0);
	tglRotatef(roll, 0, 1, 0);
}
Beispiel #6
0
void GfxTinyGL::drawSprite(const Sprite *sprite) {
	tglMatrixMode(TGL_TEXTURE);
	tglLoadIdentity();
	tglMatrixMode(TGL_MODELVIEW);
	tglPushMatrix();
	tglTranslatef(sprite->_pos.x(), sprite->_pos.y(), sprite->_pos.z());

	TGLfloat modelview[16];
	tglGetFloatv(TGL_MODELVIEW_MATRIX, modelview);

	// We want screen-aligned sprites so reset the rotation part of the matrix.
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (i == j) {
				modelview[i * 4 + j] = 1.0f;
			} else {
				modelview[i * 4 + j] = 0.0f;
			}
		}
	}
	tglLoadMatrixf(modelview);

	tglDisable(TGL_LIGHTING);

	tglBegin(TGL_POLYGON);
	tglTexCoord2f(0.0f, 0.0f);
	tglVertex3f(sprite->_width / 2, sprite->_height, 0.0f);
	tglTexCoord2f(0.0f, 1.0f);
	tglVertex3f(sprite->_width / 2, 0.0f, 0.0f);
	tglTexCoord2f(1.0f, 1.0f);
	tglVertex3f(-sprite->_width / 2, 0.0f, 0.0f);
	tglTexCoord2f(1.0f, 0.0f);
	tglVertex3f(-sprite->_width / 2, sprite->_height, 0.0f);
	tglEnd();

	tglEnable(TGL_LIGHTING);

	tglPopMatrix();
}
Beispiel #7
0
// below funcs lookAt, transformPoint and tgluProject are from Mesa glu sources
static void lookAt(TGLfloat eyex, TGLfloat eyey, TGLfloat eyez, TGLfloat centerx,
		TGLfloat centery, TGLfloat centerz, TGLfloat upx, TGLfloat upy, TGLfloat upz) {
	TGLfloat m[16];
	TGLfloat x[3], y[3], z[3];
	TGLfloat mag;

	z[0] = eyex - centerx;
	z[1] = eyey - centery;
	z[2] = eyez - centerz;
	mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
	if (mag) {
		z[0] /= mag;
		z[1] /= mag;
		z[2] /= mag;
	}

	y[0] = upx;
	y[1] = upy;
	y[2] = upz;

	x[0] = y[1] * z[2] - y[2] * z[1];
	x[1] = -y[0] * z[2] + y[2] * z[0];
	x[2] = y[0] * z[1] - y[1] * z[0];

	y[0] = z[1] * x[2] - z[2] * x[1];
	y[1] = -z[0] * x[2] + z[2] * x[0];
	y[2] = z[0] * x[1] - z[1] * x[0];

	mag = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
	if (mag) {
		x[0] /= mag;
		x[1] /= mag;
		x[2] /= mag;
	}

	mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
	if (mag) {
		y[0] /= mag;
		y[1] /= mag;
		y[2] /= mag;
	}

#define M(row,col)  m[col * 4 + row]
	M(0, 0) = x[0];
	M(0, 1) = x[1];
	M(0, 2) = x[2];
	M(0, 3) = 0.0f;
	M(1, 0) = y[0];
	M(1, 1) = y[1];
	M(1, 2) = y[2];
	M(1, 3) = 0.0f;
	M(2, 0) = z[0];
	M(2, 1) = z[1];
	M(2, 2) = z[2];
	M(2, 3) = 0.0f;
	M(3, 0) = 0.0f;
	M(3, 1) = 0.0f;
	M(3, 2) = 0.0f;
	M(3, 3) = 1.0f;
#undef M
	tglMultMatrixf(m);

	tglTranslatef(-eyex, -eyey, -eyez);
}