Ejemplo n.º 1
0
void CSimpleEnemy::setupInternal() {
	switch (m_eEnemyType) {
	case ET_GREEN_SWORD:
		createTool(CPlayerTool::TOOL_SWORD, true);
		createShield(CShield::ST_SIMPLE_SHIELD, true);
		setCurAndMaxHP(HP_ONE_HEART);
		m_bSwordsDrawn = true;
		break;
    case ET_BLOCKER:
		createTool(CPlayerTool::TOOL_SWORD, true);
		createShield(CShield::ST_SIMPLE_SHIELD, true);
		m_bSwordsDrawn = true;
		animStartBlock();
		setCurAndMaxHP(HP_INFINITY);
		dynamic_cast<CSimpleEnemyController*>(m_pCharacterController)->stun();
		m_uiTakeDamageFlags = CDamage::DMG_NONE;
		break;
	}
}
/*******************************************************************
	       City Modelling Program
********************************************************************/
//////////
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
//#include <gl/glut.h>
#include "Dependencies\freeglut\freeglut.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <utility>
#include <vector>
#include "VECTOR3D.h"

#include "TerrainGrid.h"
#include "Mesh.h"
#include "RGBpixmap.h"
#include "ComplexObj.h"

void initOpenGL();
void display(void);
void reshape(int w, int h);
void mouse(int button, int state, int x, int y);
void mouseMotionHandler(int xMouse, int yMouse);
void keyboard(unsigned char key, int x, int y);
void functionKeys(int key, int x, int y);
void timer(int value);
VECTOR3D ScreenToWorld(int x, int y);
void updateCameraPos();
void limitCameraAngle();

bool hasCollision(const Mesh* a, Mesh* b[], Mesh* c[], Mesh* d[], float offset, int sizeb, int sizec, int sized);
bool hasObjCollision(const Mesh* a, ComplexObj *cobj[], int sizee);
void createBoundaryWalls();
void createInnerWalls();
void createDoors();

static int currentButton;
static unsigned char currentKey;
#define M_PI 3.14159265358979323846
const float FPS = 30.0;

// City Interaction State Variable
enum Action {TRANSLATE, ROTATE, RAISE, SCALE, EXTRUDE, SELECT, MULTIPLESELECT, DESELECT_ALL, NAVIGATE};
enum Action currentAction = TRANSLATE;

GLfloat light_position0[] = {12.0, 6.0,-12.0,1.0};
GLfloat light_position1[] = {-12.0, 6.0,12.0,1.0};
GLfloat light_diffuse[]   = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[]  = {1.0, 1.0, 1.0, 1.0};
GLfloat light_ambient[]   = {0.2, 0.2, 0.2, 1.0};

// Person mesh - head + body
Mesh *personBody;
GLUquadricObj *personHead;

// City terrain mesh
TerrainGrid *terrainGrid = NULL;
int gridSize = 16;

// Wall Meshes
Mesh *boundaryWalls[4]; // boundary walls that surround the world
Mesh *innerWalls[20];   // inner walls of the rooms & world
Mesh *doors[20];   // inner walls of the rooms & world
float wallHeight = 1.0f; // wall height of all (boundary, inner) walls
int numBoundaryWalls = 0, numInnerWalls = 0, numDoors = 0;
RGBpixmap floorPix[1], boundaryWallPix[1], innerWallPix[1], doorPix[2];

// Room Objects
ComplexObj *cobj[12];
//int nextobj = 0;               //index to objects array to store next cube
ComplexObj *navobj;  //selected object in NAVIGATE mode
bool objCollision = false; // state to toggle avatar and object collision

float trsize = 0.2, scsize = 0.2, rosize = 5.0;      //translation, scaling and rotation angle deltas

// Textures 
GLuint textureId;

// Camera Control
VECTOR3D lookFrom;
VECTOR3D lookAt;
VECTOR3D up;

float radius = 8;			// Camera Distance
float lookFromx = 0;		// Camera X Position
float lookFromy = 0;	// Camera Y Position
float lookFromz = radius;		// Camera Z Position

float angleTheta = 0;		// Camera X angle
float anglePhi = 80;		// Camera Y angle

float upx = 0;			// Up Vector
float upy = 1;
float upz = 0;

float lookAtx = 0;		// Camera is looking at
float lookAty = 0;
float lookAtz = 0;

float camerax = 0;		// Camera X Position
float cameray = 0;	// Camera Y Position
float cameraz = radius;		// Camera Z Position

static float zoomFactor = 1.0; 

float xbefore;			// Previous X position of tank
float zbefore;			// Previous Y position of tank

float collision_offset = 0.4;

//GLint glutWindowWidth = 750;
//GLint glutWindowHeight = 500;
GLint glutWindowWidth = 1200;
GLint glutWindowHeight = 800;
GLint viewportWidth = glutWindowWidth;
GLint viewportHeight = glutWindowHeight;

// Wolrd Boundaries
GLdouble worldLeftBase  =  -8.0;
GLdouble worldRightBase =  8.0;
GLdouble worldBottomBase=  -8.0;
GLdouble worldTopBase   =  8.0;

// World view boundaries
GLdouble wvLeftBase		=  worldLeftBase, 
         wvRightBase	=  worldRightBase,
		 wvBottomBase	=  worldBottomBase, 
		 wvTopBase		=  worldTopBase;

int main(int argc, char **argv){
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  //glutInitWindowSize(750, 500);
  glutInitWindowSize(glutWindowWidth, glutWindowHeight);
  glutInitWindowPosition(100, 100);
  glutCreateWindow("Room Navigator");

  floorPix[0].readBMPFile("FloorWood01.bmp");
  boundaryWallPix[0].readBMPFile("WallBrick02.bmp");
  innerWallPix[0].readBMPFile("WallWood01.bmp");
  doorPix[0].readBMPFile("Door01L.bmp");
  doorPix[1].readBMPFile("Door01R.bmp");

  initOpenGL();

  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutMouseFunc(mouse);
  glutMotionFunc(mouseMotionHandler);
  glutKeyboardFunc(keyboard);
  glutSpecialFunc(functionKeys);
  glutTimerFunc(1000.0 / FPS, timer, 0);
  glutMainLoop();
  return 0;
}

int width, height;
VECTOR3D scale;
VECTOR3D trans;
VECTOR3D angles;

// Setup openGL */
void initOpenGL(){
  glViewport(0, 0, (GLsizei) viewportWidth, (GLsizei) viewportHeight);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(60.0*zoomFactor,(float)viewportWidth/(float)viewportHeight,0.2,80.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // Set up and enable lighting
  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
  
  glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
  glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);

  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_SMOOTH);
  glClearColor(0.6, 0.6, 0.6, 0.0);  
  glClearDepth(1.0f);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  //Nice perspective.
  glHint(GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST);
  
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  updateCameraPos();
  gluLookAt(lookFromx, lookFromy, lookFromz,lookAtx, lookAty, lookAtz, upx, upy, upz);
  
  //Texture
  glGenTextures(1, &textureId);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // store pixels by byte	
  glBindTexture(GL_TEXTURE_2D, textureId); // select current texture (0)
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  // Set up Terrain Grid
  VECTOR3D origin = VECTOR3D(-16.0f, 0.0f, 16.0f);
  terrainGrid = new TerrainGrid(gridSize, 32.0); // gridsize = 16
  terrainGrid->InitGrid(gridSize, origin, 32.0, 32.0);

  createBoundaryWalls(); // Create boundary walls
  createInnerWalls(); // create inner walls
  createDoors(); // create doors

  // Create a person (Head+Body) - initially oriented along z axis direction (-ve z dir (0,0,-1) & ccw => angles.y = 0)
  scale.x = 0.5;   scale.y = 1.4;   scale.z = 0.2;
  trans.x = -2.0;   trans.y = 0;     trans.z = 8.0;
  personBody = createMesh(scale, trans, 1.0, 1);
  personBody->angles.x = personBody->angles.y = personBody->angles.z = 0.0;
  personBody->selected = true;

  // Create room objects (4 kinds)
  for (int i = 0; i < 12; i++){
	  cobj[i] = createObj();
  }
  createShield(cobj[0]); cobj[0]->translation.Set( 0.0, 2.0,  15.0); cobj[0]->angles.Set(0.0, 180.0, 0.0);
  createShield(cobj[1]); cobj[1]->translation.Set(-8.0, 2.0, -15.0);
  createShield(cobj[2]); cobj[2]->translation.Set( 8.0, 2.0, -15.0);
  createTable( cobj[3]); cobj[3]->translation.Set(14.0, 0.0, 2.0);
  createTable( cobj[4]); cobj[4]->translation.Set(14.0, 0.0,-2.0);
  createTable( cobj[5]); cobj[5]->translation.Set(-14.0,0.0,-2.0);
  createVase(  cobj[6]); cobj[6]->translation.Set(14.0, 0.0, 4.0);
  createVase(  cobj[7]); cobj[7]->translation.Set(-14.0, 0.0,-14.0);
  createVase(  cobj[8]); cobj[8]->translation.Set(14.0, 0.0,-14.0);
  createPicFrame(cobj[9]);  cobj[9]->translation.Set(8.0, 2.0, 15.0);    cobj[9]->angles.Set(0.0, 180.0, 0.0);
  createPicFrame(cobj[10]); cobj[10]->translation.Set(-15.0, 2.0, -8.0); cobj[10]->angles.Set(0.0, 90.0, 0.0);
  createPicFrame(cobj[11]); cobj[11]->translation.Set(15.0, 2.0, -8.0);  cobj[11]->angles.Set(0.0, -90.0, 0.0);
}