void setupRC() { expCounter = counterLoader(); //BG: glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Enable depth testing so things won't look effed up: glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); //Initialize stock shaders from GLTools: shaderManager.InitializeStockShaders(); //Move cam back: cameraFrame.MoveForward(-30.0f); cameraFrame.MoveRight(-5.0f); cameraFrame.MoveUp(-8.0f); newDeskButton.init(20, 80, 165, 70, "Assets/button_new_desk165x70.tga"); removeDeskButton.init(208, 80, 175, 67, "Assets/button_remove_desk175x67.tga"); exportButton.init(403, 80, 168, 67, "Assets/button_export168x67.tga"); M3DVector4f deskShine = {0.5, 0.5, 0.5, 1.0}; M3DVector4f deskColor = {0.0f, 0.0f, 0.5f, 1.0f}; hlGrid.init(0.0f, 0.0f, 0.0f, C_DM/2); cRoom.init(); stuDesks.init(deskColor, deskShine, C_DM/2); }
void LeadingRole::beingAttacked() { if(state == normalState) { state = beingAttackedState; ySpeed = 0.5; xSpeed = 0.3; } if(state == beingAttackedState) { ySpeed = ySpeed-0.1; frame.MoveUp(ySpeed); frameCamera.MoveUp(ySpeed*scaleY); if(faceRight == true) { frame.MoveForward(-xSpeed); frameCamera.MoveRight(xSpeed*scaleX); } else { frame.MoveForward(-xSpeed); frameCamera.MoveRight(-xSpeed*scaleX); } bool collision = collisionGround(); if(collision == true) { frame.MoveUp(-ySpeed); frameCamera.MoveUp(-ySpeed*scaleY); while(collision == true) { frame.MoveUp(0.1); frameCamera.MoveUp(0.1*scaleY); collision = collisionGround(); } xSpeed = 0; ySpeed = 0; state = normalState; //cout << "normal" << endl; } } }
void LeadingRole::jump() { if(state == normalState) { ySpeed = 0.8; state = jumpState; rightHandRotate[0] = 45; leftLegRotate[0] = leftHandRotate[0] = -rightHandRotate[0]; rightLegRotate[0] = rightHandRotate[0]; } else if(state == jumpState) { ySpeed = ySpeed-0.1; } frame.MoveUp(ySpeed); frameCamera.MoveUp(ySpeed*scaleY); bool groundCollision = false; for(int i=0; i<groundObject.size(); i++) { //cout << test2.boundingBox.yMin << ";" << groundObject[i].boundingBox.yMax << endl; if(checkCollisionByObjectInGame(*this, groundObject[i])) groundCollision = true; } if(groundCollision == true) { frame.MoveUp(-ySpeed); frameCamera.MoveUp(-ySpeed*scaleY); if(ySpeed < 0) { state = normalState; rightHandRotate[0] = 0; leftLegRotate[0] = leftHandRotate[0] = -rightHandRotate[0]; rightLegRotate[0] = rightHandRotate[0]; return; } ySpeed = 0; } //glutTimerFunc(33, jump, i+1); //glutPostRedisplay(); }
void handleInput(CStopWatch &inputTimer) { // Exit if (in.keyPressed(sf::Keyboard::Escape)) exit(0); // Camera movement float elapsedTime = inputTimer.GetElapsedSeconds() * 1.5f; inputTimer.Reset(); if (mouseActive) { if (in.keyPressed(sf::Keyboard::W)) cameraFrame.MoveForward(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::S)) cameraFrame.MoveForward(-camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::A)) cameraFrame.MoveRight(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::D)) cameraFrame.MoveRight(-camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::Space)) cameraFrame.MoveUp(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::LControl)) cameraFrame.MoveUp(-camSpeed*elapsedTime); } else { if (in.keyPressed(sf::Keyboard::W)) cameraFrame.MoveUp(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::S)) cameraFrame.MoveUp(-camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::A)) cameraFrame.MoveRight(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::D)) cameraFrame.MoveRight(-camSpeed*elapsedTime); } }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); viewFrame.MoveForward(-155.0f); viewFrame.MoveUp(20.0f); grassShader = gltLoadShaderPairWithAttributes("Grass.vs", "Grass.fs", 1, GLT_ATTRIBUTE_VERTEX, "vVertex"); locMVP = glGetUniformLocation(grassShader, "mvpMatrix"); glUseProgram(grassShader); glUniform1i(glGetUniformLocation(grassShader, "length_texture"), 0); glUniform1i(glGetUniformLocation(grassShader, "orientation_texture"), 1); glUniform1i(glGetUniformLocation(grassShader, "grasspalette_texture"), 2); glUniform1i(glGetUniformLocation(grassShader, "grasscolor_texture"), 3); glUniform1i(glGetUniformLocation(grassShader, "bend_texture"), 4); static const GLfloat grass_blade[] = { -0.3f, 0.0f, 0.3f, 0.0f, -0.20f, 1.0f, 0.1f, 1.3f, -0.05f, 2.3f, 0.0f, 3.3f }; // Greate a vertex array object and a vertex buffer for the quad // including position and texture coordinates glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(grass_blade), grass_blade, GL_STATIC_DRAW); glVertexAttribPointer(GLT_ATTRIBUTE_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(GLT_ATTRIBUTE_VERTEX); // glGenTextures(1, &length_texture); glBindTexture(GL_TEXTURE_2D, length_texture); GLint w, h, c; GLenum f; void * bits = gltReadTGABits("length.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); glGenTextures(1, &orientation_texture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, orientation_texture); bits = gltReadTGABits("orientation.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); glGenTextures(1, &grasspalette_texture); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_1D, grasspalette_texture); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB8, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, grasspalette_data); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glGenTextures(1, &grasscolor_texture); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, grasscolor_texture); bits = gltReadTGABits("color.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); glGenTextures(1, &bend_texture); glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, bend_texture); bits = gltReadTGABits("bend.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); }
/////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { GLbyte *pBytes; GLint nWidth, nHeight, nComponents; GLenum format; shaderManager.InitializeStockShaders(); // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glLineWidth(2.5f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); cameraFrame.MoveUp(6.0f); cameraFrame.RotateLocalX(float(m3dDegToRad(20.0f))); MakeCube(cubeBatch); MakeFloor(floorBatch); // Make top topBlock.Begin(GL_TRIANGLE_FAN, 4, 1); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 0.0f); topBlock.Vertex3f(-1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 0.0f); topBlock.Vertex3f(1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 1.0f); topBlock.Vertex3f(1.0f, 1.0f, -1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 1.0f); topBlock.Vertex3f(-1.0f, 1.0f, -1.0f); topBlock.End(); // Make Front frontBlock.Begin(GL_TRIANGLE_FAN, 4, 1); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 0.0f); frontBlock.Vertex3f(-1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 0.0f); frontBlock.Vertex3f(1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 1.0f); frontBlock.Vertex3f(1.0f, 1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 1.0f); frontBlock.Vertex3f(-1.0f, 1.0f, 1.0f); frontBlock.End(); // Make left leftBlock.Begin(GL_TRIANGLE_FAN, 4, 1); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, -1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, -1.0f); leftBlock.End(); // Create shadow projection matrix GLfloat floorPlane[] = { 0.0f, 1.0f, 0.0f, 1.0f}; m3dMakePlanarShadowMatrix(shadowMatrix, floorPlane, vLightPos); // Load up four textures glGenTextures(4, textures); // Wood floor pBytes = gltReadTGABits("floor.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // One of the block faces pBytes = gltReadTGABits("Block4.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Another block face pBytes = gltReadTGABits("block5.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Yet another block face pBytes = gltReadTGABits("block6.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); }
void LeadingRole::draw() { if(timeCount%100 == 0 && health<maxHealth) { health+=10; } if(state == jumpState) { jump(); } else if(state == beingAttackedState) { beingAttacked(); } else if(state == attackState1 || state == attackState2) { attack(); } else { ySpeed = ySpeed-0.1; frame.MoveUp(ySpeed); frameCamera.MoveUp(ySpeed*scaleY); bool groundCollision = collisionGround(); if(groundCollision == true) { frame.MoveUp(-ySpeed); frameCamera.MoveUp(-ySpeed*scaleY); ySpeed = 0; } } if(moveS == 0) { walkFoward(0.15f); } else if(moveS == 1) { walkFoward(-0.15f); } glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); extern GLuint textures[1]; int textureNum = getTextureNumMap()["leadingRole"]; glBindTexture(GL_TEXTURE_2D, textures[textureNum]); glPushMatrix(); //health line glPushMatrix(); glTranslatef(0, 1, -0.5); glColor3f(1, 0, 0); double lineLength = 1.2*health/maxHealth; glBegin(GL_QUADS); glVertex3d(0, -0.1, 0); glVertex3d(0, -0.1, lineLength); glVertex3d(0, 0.1, lineLength); glVertex3d(0, 0.1, 0); glEnd(); glColor3f(1, 1, 1); glPopMatrix(); glmDraw(head, GLM_SMOOTH | GLM_TEXTURE); glPushMatrix(); glTranslatef(0.045, -0.38, -0.32); glmDraw(body, GLM_SMOOTH | GLM_TEXTURE); glPopMatrix(); glPushMatrix(); glTranslatef(-0.325,-0.68,-0.09); glScalef(0.8, 0.8, 0.8); glTranslatef(0.2, 0.3, 0); glRotatef(rightHandRotate[0], 1, 0, 0); glTranslatef(-0.2, -0.3, 0); glmDraw(rightHand, GLM_SMOOTH | GLM_TEXTURE); glPushMatrix(); glTranslatef(-0.025,-0.33,0.75); glmDraw(axe, GLM_SMOOTH | GLM_TEXTURE); glPopMatrix(); glPopMatrix(); glPushMatrix(); glTranslatef(0.33,-0.036,-0.07); glScalef(1.47, 1.47, 1.47); glTranslatef(-0, -0.25, 0); glRotatef(leftHandRotate[0], 1, 0, 0); glTranslatef(0, 0.25, 0); glmDraw(leftHand, GLM_SMOOTH | GLM_TEXTURE); glPopMatrix(); glPushMatrix(); glTranslatef(-0.12,-1.1,0); glScalef(0.18, 0.18, 0.18); glTranslatef(0, 1, 0); glRotatef(rightLegRotate[0], 1, 0, 0); glTranslatef(0, -1, 0); glmDraw(rightLeg, GLM_SMOOTH | GLM_TEXTURE); glPopMatrix(); glPushMatrix(); glTranslatef(0.12,-1.1,0); glScalef(0.18, 0.18, 0.18); glTranslatef(0, 1, 0); glRotatef(leftLegRotate[0], 1, 0, 0); glTranslatef(0, -1, 0); glmDraw(leftLeg, GLM_SMOOTH | GLM_TEXTURE); glPopMatrix(); glPopMatrix(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); }