Beispiel #1
0
/*
	t_point3	rev;

	matrix_identity(matrix);
	matrix_rotate(matrix, new_point3(1, 0, 0), camera->pitch);
	matrix_rotate(matrix, new_point3(0, 1, 0), camera->yaw);
	matrix_rotate(matrix, new_point3(0, 0, 1), camera->roll);
	rev = new_point3(camera->pos[0], camera->pos[1], camera->pos[2]);
	rev = vec_rev_sign(rev);
	matrix_translate(matrix, rev.x, rev.y, rev.z);
*/
Matrix		Matrix::createViewMatrix(Camera camera)	{
	Matrix		m;
	float		*cameraPos = camera.getPosition();

	m.rotate(Vec3(1, 0, 0), (float) TO_RADIAN(camera.getPitch()));
	m.rotate(Vec3(1, 0, 0), (float) TO_RADIAN(camera.getYaw()));
	m.rotate(Vec3(1, 0, 0), (float) TO_RADIAN(camera.getRoll()));

	m.translate(-cameraPos[0], -cameraPos[1], -cameraPos[2]);
	return (m);
}
glm::mat4 Model::get_model_matrix( GLfloat angle )
{
	angle = TO_RADIAN(angle);

	this->model_matrix = glm::rotate(this->model_matrix, angle,
			glm::vec3(1.0f, 0.3f, 0.5f));

	return this->model_matrix;
}
Beispiel #3
0
Matrix4& MakeProjectionMatrix( Matrix4& out, float zn, float zf, float fov, float aspect )
{
	ZeroMemory(&out, sizeof(Matrix4));

	float yScale = 1.0f / tan(TO_RADIAN(fov) / 2.0f);
	float xScale = yScale / aspect;
	float zScale = zf / (zf - zn);

	out.m11 = xScale;
	out.m22 = yScale;
	out.m33 = zScale;
	out.m34 = 1.0f;
	out.m43 = -zn * zScale;

	return out;
}
Beispiel #4
0
Matrix4& MakeRotationMatrixZ( Matrix4& out, float angle )
{
	ZeroMemory(&out, sizeof(Matrix4));

	float radian = TO_RADIAN(angle);
	float sine = sin(radian);
	float cosine = cos(radian);

	out.m11 = cosine;
	out.m12 = sine;
	out.m21 = -sine;
	out.m22 = cosine;
	out.m33 = 1.0f;
	out.m44 = 1.0f;

	return out;
}
Beispiel #5
0
//-----------------------------------------------------------------------------
// Name: QuaternionAxisToAxis
// Desc: Axis to axis quaternion 
//       Takes two points on unit sphere an angle THETA apart, returns
//       quaternion that represents a rotation around cross product by theta.
//-----------------------------------------------------------------------------
void quater::axisToAxis( const vector3& vFrom, const vector3& vTo)
{
	vector3 vA, vB, vHalf;
	vA.normalize(vFrom);
	vB.normalize(vTo);
	//두개가 180각이 되면 singular가 되서 90도가 되는 축을 임의로 계산해 줘야됨
	if(vA%vB<-0.999){
		vB*=-1;
		quater q;
		q.axisToAxis(vA, vB);
		//임의로 z축으로 180도 돌림.
		mult(quater(TO_RADIAN(180), vector3(0,0,1)), q);
		return;
	}else{
		vHalf.add(vA,vB);
		vHalf.normalize();
	}
	unitAxisToUnitAxis2(vA, vHalf);
}
Beispiel #6
0
void PowerUp::draw() const
{
    glPushMatrix();
	glTranslatef((float)_loc[0]-FIELD_SIZE/2.0f+0.5f,0.0f,(float)_loc[1]-FIELD_SIZE/2.0f+0.5f); //move to right place
	//glTranslatef(-2.0f, 1.0f, 0.0f);
	glTranslatef(0.0f, 0.1f * std::sin(TO_RADIAN(PowerUp::_angle) * 2.0f), 0.0f); // bounce up and down
	glRotatef(PowerUp::_angle, 0.0f, 1.0f, 0.0f); // spin around

	if (_type == POWERUP_HP)
	{
		GLUquadric *quad = gluNewQuadric();
		// red cross
		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
		glPushMatrix();
		glutSolidCube(0.2f);
		glTranslatef(-0.2f, 0.0f, 0.0f);
		glutSolidCube(0.2f);
		glTranslatef(0.4f, 0.0f, 0.0f);
		glutSolidCube(0.2f);
		glTranslatef(-0.2f, -0.2f, 0.0f);
		glutSolidCube(0.2f);
		glTranslatef(0.0f, 0.4f, 0.0f);
		glutSolidCube(0.2f);
		glPopMatrix();
		// white cylinder
		glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
		glTranslatef(0.0f, 0.0f, -0.1f);
		gluCylinder(quad, 0.5f, 0.5f, 0.2f, 20, 2);
		for (int i = 0; i < 2; i++)
		{
			glPushMatrix();
			glTranslatef(0.0f, 0.0f, i * 0.2f);
			// white disk
			glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
			gluDisk(quad, 0.0f, 0.5f, 20, 2);
			glPopMatrix();
		}
	}
	else if (_type == POWERUP_GRENADE)
	{
		GLUquadric *quad = gluNewQuadric();
		// green sphere
		glColor4f(0.0f, 0.2f, 0.0f, 1.0f);
		glutSolidSphere(0.1f, 20, 20);
		// white cylinder
		glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
		glTranslatef(0.0f, 0.0f, -0.1f);
		gluCylinder(quad, 0.5f, 0.5f, 0.2f, 20, 2);
		for (int i = 0; i < 2; i++)
		{
			glPushMatrix();
			glTranslatef(0.0f, 0.0f, i * 0.2f);
			// white disk
			glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
			gluDisk(quad, 0.0f, 0.5f, 20, 2);
			glPopMatrix();
		}
	}
	// add other power ups here
	else
	{
		GLUquadric *quad = gluNewQuadric();
		glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
		gluSphere(quad, 0.5f, 10, 10);
	}

    glPopMatrix();
}
Beispiel #7
0
void Enemy::updateAction(Landscape* landscape, Point playerPosition)
{
	_AStarFields.clear();
	_AStarAimField = -1;
	_AStarBestField = -1;

	// reset all
	setAccelerating(false);
	setDecelerating(false);
	setAcceleratingLeft(false);
	setAcceleratingRight(false);
	setIncreasingElevation(false);
	setDecreasingElevation(false);
	setIncreasingAzimuth(false);
	setDecreasingAzimuth(false);
	setIncreasingPower(false);
	setDecreasingPower(false);
	setShootingMG(false);
	setShootingGrenade(false);

	// get surrounding of this enemy
	TerrainType** surroundings = landscape->getMap(_position, AI_VIEW_DISTANCE);

	// make sure Point.w is 1 for _position and playerPosition
	_position.x /= _position.w;
	_position.y /= _position.w;
	_position.z /= _position.w;
	_position.w = 1.0f;
	playerPosition.x /= playerPosition.w;
	playerPosition.y /= playerPosition.w;
	playerPosition.z /= playerPosition.w;
	playerPosition.w = 1.0f;

	// field of this enemy
	int x = (int)_position.x + FIELD_SIZE / 2;
	int z = (int)_position.z + FIELD_SIZE / 2;

	//// if this enemy is facing a building, just go backwards and do nothing else
	//TerrainType t11 = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE];
	//TerrainType t21 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1];
	//TerrainType t31 = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE];
	//TerrainType t41 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1];
	//TerrainType t12 = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE];
	//TerrainType t22 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2];
	//TerrainType t32 = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE];
	//TerrainType t42 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2];
	//if (_speed >= 0.0f && ((_angle < 45.0f || 315.0f <= _angle) && (surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE] == BUILDING || surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE] == BUILDING)
	//	|| 45.0f <= _angle && _angle < 135.0f && (surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1] == BUILDING || surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2] == BUILDING)
	//	|| 135.0f <= _angle && _angle < 225.0f && (surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE] == BUILDING || surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE] == BUILDING)
	//	|| 225.0f <= _angle && _angle < 315.0f && (surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1] == BUILDING || surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2] == BUILDING)))
	//{
	//	setDecelerating(true);
	//	return;
	//}

	// field of player
	int x_player = (int)playerPosition.x + FIELD_SIZE / 2;
	int z_player = (int)playerPosition.z + FIELD_SIZE / 2;

	// calculate aim vector = vector from this enemy's position to player's position
	Vector3D aim = Vector3D(playerPosition.x - _position.x, 0.0f, playerPosition.z - _position.z);
	float aimAngle = TO_DEGREE(atan2f(-aim.z, aim.x));
	if (aimAngle >= 360.0f)
		aimAngle -= 360.0f;
	else if (aimAngle < 0.0f)
		aimAngle += 360.0f;
	float aimDist = sqrtf(aim.x * aim.x + aim.z * aim.z);

	// find and store all fields in surrounding having a building (used for visibility check)
	IntVector buildingFieldsOfSurrounding;
	for (int ii = 0; ii < 2 * AI_VIEW_DISTANCE + 1; ii++)
	{
		for (int jj = 0; jj < 2 * AI_VIEW_DISTANCE + 1; jj++)
		{
			if (surroundings[ii][jj] == BUILDING)
				buildingFieldsOfSurrounding.push_back((z + jj - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + ii - AI_VIEW_DISTANCE));
		}
	}

	// check if player is within surrounding
	bool inSurrounding = x - AI_VIEW_DISTANCE <= x_player && x_player <= x + AI_VIEW_DISTANCE && z - AI_VIEW_DISTANCE <= z_player && z_player <= z + AI_VIEW_DISTANCE;
	bool visible = false;

	if (inSurrounding)
	{
		// PLAYER IS IN SURROUNDING

		// check if player is directly visible
		visible = isVisible(_position.x, _position.z, playerPosition.x, playerPosition.z, buildingFieldsOfSurrounding);

		if (visible)
		{
			// PLAYER IS DIRECTLY VISIBLE -> aim at player and shoot (do not drive)

			// aim at player
			if (_angle < aimAngle && aimAngle - _angle <= 180.0f || _angle > aimAngle && _angle - aimAngle > 180.0f)
				setAcceleratingLeft(true);
			else
				setAcceleratingRight(true);

			// shoot with machine gun
			setShootingMG(true);
		}

		// shoot grenade if player tank is near (or aim grenade launcher if not ready)
		if (aimDist <= AI_GRENADE_DIST && _hasGrenadeLauncherEnabled)
		{
			if (_firingStateGrenade == READY)
				setShootingGrenade(true);
			else
			{
				float totalAngle = _angle + _azimuth;
				if (totalAngle >= 360.0f)
					totalAngle -= 360.0f;
				else if (totalAngle < 0.0f)
					totalAngle += 360.0f;
				if (totalAngle < aimAngle && aimAngle - totalAngle <= 180.0f || totalAngle > aimAngle && totalAngle - aimAngle > 180.0f)
					setIncreasingAzimuth(true);
				else
					setDecreasingAzimuth(true);

				if (_elevation > 20.0f)
					setDecreasingElevation(true);
			}
		}
	}

	if (!inSurrounding || !visible)
	{
		// PLAYER IS OUTSIDE OF SURROUNDING OR NOT DIRECTLY VISIBLE -> try to get as near as possible to player (do not shoot)

		// find goal state ( = field within surroundings which is closest to player position)
		int i_goal = AI_VIEW_DISTANCE;
		int j_goal = AI_VIEW_DISTANCE;
		float d, min_dist = dist(x, z, playerPosition);
		for (int ii = 0; ii < 2 * AI_VIEW_DISTANCE + 1; ii++)
		{
			for (int jj = 0; jj < 2 * AI_VIEW_DISTANCE + 1; jj++)
			{
				if (surroundings[ii][jj] != BUILDING)
				{
					d = dist(x + ii - AI_VIEW_DISTANCE, z + jj - AI_VIEW_DISTANCE, playerPosition);
					if (d < min_dist)
					{
						min_dist = d;
						i_goal = ii;
						j_goal = jj;
					}
				}
			}
		}

		// variables needed in A* search
		Fringe fringe;
		unsigned int step = 0;
		AStarNode *node = new AStarNode(0.0f, aimDist, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, true, NULL);
		int i, j;
		bool fieldVisible;

		// add initial state to fringe
		fringe.push(node);

		// do actual A* search
		while (step < AI_MAX_STEPS && !fringe.empty())
		{
			node = fringe.top();
			fringe.pop();
			i = node->i;
			j = node->j;

			if (DEBUG_ENEMY)
				_AStarFields.push_back((z + j - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + i - AI_VIEW_DISTANCE));

			// goal test (stop iteration when goal is reached)
			if (i == i_goal && j == j_goal)
				break;

			// expand node
			if (0 <= i - 1 && surroundings[i - 1][j] != BUILDING && !node->hasVisited(i - 1, j))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i - 1, j, x, z, surroundings);
				else
					fieldVisible = false;
				//fringe.push(AStarNode(node.cost_so_far + 1.0f, dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
				//	i - 1, j, fieldVisible ? i - 1 : node.i_aim, fieldVisible ? j : node.j_aim, fieldVisible));
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
					i - 1, j, fieldVisible ? i - 1 : node->i_aim, fieldVisible ? j : node->j_aim, fieldVisible, node));
			}
			if (i + 1 < 2 * AI_VIEW_DISTANCE + 1 && surroundings[i + 1][j] != BUILDING && !node->hasVisited(i + 1, j))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i + 1, j, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i + 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i + 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
					i + 1, j, fieldVisible ? i + 1 : node->i_aim, fieldVisible ? j : node->j_aim, fieldVisible, node));
			}
			if (0 <= j - 1 && surroundings[i][j - 1] != BUILDING && !node->hasVisited(i, j - 1))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i, j - 1, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - AI_VIEW_DISTANCE, z + j - 1 - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - AI_VIEW_DISTANCE, z + j - 1 - AI_VIEW_DISTANCE, playerPosition),
					i, j - 1, fieldVisible ? i : node->i_aim, fieldVisible ? j - 1 : node->j_aim, fieldVisible, node));
			}
			if (j + 1 < 2 * AI_VIEW_DISTANCE + 1 && surroundings[i][j + 1] != BUILDING && !node->hasVisited(i, j + 1))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i, j + 1, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - AI_VIEW_DISTANCE, z + j + 1 - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - AI_VIEW_DISTANCE, z + j + 1 - AI_VIEW_DISTANCE, playerPosition),
					i, j + 1, fieldVisible ? i : node->i_aim, fieldVisible ? j + 1 : node->j_aim, fieldVisible, node));
			}

			step++;
		}

		if (DEBUG_ENEMY)
		{
			_AStarAimField = (z + node->j_aim - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + node->i_aim - AI_VIEW_DISTANCE);
			_AStarBestField = (z + node->j - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + node->i - AI_VIEW_DISTANCE);
			std::cout << step << std::endl;
		}

		// set new aim according to A* search (aim at farthest visible field in path to the chosen node)
		aim = Vector3D(x + node->i_aim - AI_VIEW_DISTANCE - FIELD_SIZE / 2 + 0.5f - _position.x,
			0.0f,
			z + node->j_aim - AI_VIEW_DISTANCE - FIELD_SIZE / 2 + 0.5f - _position.z);
		aimAngle = TO_DEGREE(atan2f(-aim.z, aim.x));
		if (aimAngle >= 360.0f)
			aimAngle -= 360.0f;
		else if (aimAngle < 0.0f)
			aimAngle += 360.0f;
		aimDist = sqrtf(aim.x * aim.x + aim.z * aim.z);

		// calculate angle difference alpha and steer in the desired direction to reach aim
		float alpha;
		if (_angle < aimAngle)
		{
			alpha = aimAngle - _angle;
			if (alpha <= 180.0f)
				setAcceleratingLeft(true);
			else
			{
				alpha = 360.0f - alpha;
				setAcceleratingRight(true);
			}
		}
		else
		{
			alpha = _angle - aimAngle;
			if (alpha <= 180.0f)
				setAcceleratingRight(true);
			else
			{
				alpha = 360.0f - alpha;
				setAcceleratingLeft(true);
			}
		}

		//// if this enemy is facing a building, go backwards, no matter where the aim is
		//if (/*_speed >= 0.0f &&*/ ((_angle < 45.0f || 315.0f <= _angle) && surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE] == BUILDING*/
		//	|| 45.0f <= _angle && _angle < 135.0f && surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2] == BUILDING*/
		//	|| 135.0f <= _angle && _angle < 225.0f && surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE] == BUILDING*/
		//	|| 225.0f <= _angle && _angle < 315.0f && surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2] == BUILDING*/))
		//{
		//	setDecelerating(true);
		//}
		//else
		//{
			// else: using alpha, maximum turn speed and distance to aim to adapt speed to reach aim
			if (alpha != 0.0f)
			{
				float v_optimal = AI_SPEED_FACTOR * omega_max * aimDist / 2.0f / std::sin(TO_RADIAN(alpha) / 2.0f);
				if (_speed < v_optimal)
					setAccelerating(true);
				else
					setDecelerating(true);
			}
			else
				setAccelerating(true);
		//}

		// delete nodes
		while (!fringe.empty())
		{
			delete fringe.top();
			fringe.pop();
		}
	}

	// if this enemy is facing a building, go backwards
	TerrainType t11 = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE];
	TerrainType t11l = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE - 1];
	TerrainType t11r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE + 1];
	TerrainType t12 = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE];
	TerrainType t12l = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE - 1];
	TerrainType t12r = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE + 1];
	TerrainType t21 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1];
	TerrainType t21l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE - 1];
	TerrainType t21r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE - 1];
	TerrainType t22 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2];
	TerrainType t22l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE - 2];
	TerrainType t22r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE - 2];
	TerrainType t31 = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE];
	TerrainType t31l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE - 1];
	TerrainType t31r = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE + 1];
	TerrainType t32 = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE];
	TerrainType t32l = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE - 1];
	TerrainType t32r = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE + 1];
	TerrainType t41 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1];
	TerrainType t41l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE + 1];
	TerrainType t41r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE + 1];
	TerrainType t42 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2];
	TerrainType t42l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE + 2];
	TerrainType t42r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE + 2];
	if (/*_speed >= 0.0f &&*/ ((_angle < 45.0f || 315.0f <= _angle) && (t11 == BUILDING /*|| t11l == BUILDING || t11r == BUILDING*/ || t12 == BUILDING /*|| t12l == BUILDING || t12r == BUILDING*/)
		|| 45.0f <= _angle && _angle < 135.0f && (t21 == BUILDING /*|| t21l == BUILDING || t21r == BUILDING */|| t22 == BUILDING /*|| t22l == BUILDING || t22r == BUILDING*/)
		|| 135.0f <= _angle && _angle < 225.0f && (t31 == BUILDING /*|| t31l == BUILDING || t31r == BUILDING */|| t32 == BUILDING /*|| t32l == BUILDING || t32r == BUILDING*/)
		|| 225.0f <= _angle && _angle < 315.0f && (t41 == BUILDING /*|| t41l == BUILDING || t41r == BUILDING */|| t42 == BUILDING /*|| t42l == BUILDING || t42r == BUILDING*/)))
	{
		setAccelerating(false);
		setDecelerating(true);
	}

	// delete surroundings
	for (int s = 0; s < 2 * AI_VIEW_DISTANCE + 1; s++)
		delete[] surroundings[s];
	delete[] surroundings;

	// random movement
	/*setAccelerating(rand()%2==0);
	setDecelerating(rand()%2==0);
	setAcceleratingLeft(rand()%2==0);
	setAcceleratingRight(rand()%5==0);
	setIncreasingElevation(rand()%2==0);
	setDecreasingElevation(rand()%2==0);
	setIncreasingAzimuth(rand()%2==0);
	setDecreasingAzimuth(rand()%2==0);
	setIncreasingPower(rand()%2==0);
	setDecreasingPower(rand()%2==0);*/

	/*if(rand()%10==0)
		shoot();*/
}
Beispiel #8
0
int main() {

  screen s;
  color c;
 
  
  c.red = 0;
  c.green = MAX_COLOR;
  c.blue = 0;
  
  clear_screen(s);


  //octant 1
  draw_line( 0, 0, XRES-1, YRES - 75, s, c);

  //octant 2
  draw_line( 0, 0, XRES - 75, YRES-1, s, c); 

  //octant 8
  draw_line( 0, YRES-1, XRES-1, 75, s, c);  
  //octant 7
  draw_line( 0, YRES-1, XRES - 75, 0, s, c);

  c.green = 0;
  c.blue = MAX_COLOR;
  //octant 5
  draw_line( XRES - 1, YRES - 1, 0, 75, s, c);
  //octant 6
  draw_line( XRES - 1, YRES -1, 75, 0, s, c);
  //octant 4
  draw_line( XRES - 1, 0, 0, YRES - 75, s, c);
  //octant 3
  draw_line( XRES - 1, 0, 75, YRES - 1, s, c);
  
  c.blue = 0;
  c.red = MAX_COLOR;
  //y = x, y = -x
  draw_line( 0, 0, XRES - 1, YRES - 1, s, c);
  draw_line( 0, YRES - 1, XRES - 1, 0, s, c);

  //horizontal, vertical line
  draw_line( 0, YRES / 2, XRES - 1, YRES / 2, s, c);
  draw_line(XRES/2, 0, XRES/2, YRES-1, s, c);
  
//*/

  //display(s);
  save_extension(s, "lines.png");
  //save_ppm(s, "lines.ppm");

  //Draw gallery line submission
  
  clear_screen(s);
  
  
  int i, j, k;
  int theta = 30;
  int dtheta = 15;
  int x=XRES, y=0;
  int tx, ty;
  
  c.red = 0;
  c.green = 0;
  c.blue = MAX_COLOR;
  
  for(i=0; i<50; i++) {
  	
  	draw_line(0, 0, x, y, s, c);
  	
  	theta += dtheta;
  	dtheta -= (50-i);
  	if( dtheta < 2 ) {
  		dtheta = 2;
  	}
  	
  	tx = x;
  	ty = y;
  	
  	x = (int)(tx*cos( TO_RADIAN(theta) ) - ty*sin( TO_RADIAN(theta) ));
  	y = (int)(tx*sin( TO_RADIAN(theta) ) + ty*cos( TO_RADIAN(theta) ));
  	
  	//x*= i;
  	//y*= i;
  	
  }
  
  save_extension(s, "gallery_lines.png");
  
}