// camera movement. Other keyboard input is handled by keyboardControl void moveTimer(int i) { glutTimerFunc(20, &moveTimer, i); vec3 camRight = Normalize(CrossProduct(camDir, camUp)); vec3 moveDir = {0,0,0}; if (glutKeyIsDown(GLUT_KEY_W)) { moveDir = VectorAdd(moveDir, Normalize(camDir)); } if (glutKeyIsDown(GLUT_KEY_A)) { moveDir = VectorSub(moveDir, camRight); } if (glutKeyIsDown(GLUT_KEY_S)) { moveDir = VectorSub(moveDir, Normalize(camDir)); } if (glutKeyIsDown(GLUT_KEY_D)) { moveDir = VectorAdd(moveDir, camRight); } if (Norm(moveDir) > 0.0) { cam = VectorAdd(cam, ScalarMult(Normalize(moveDir), camMoveSpeed)); } if (!freeCam) cam.y = 1.0 + GetMapHeight(tm, ttex.width, ttex.height, cam.x, cam.z); }
void RuntimeTileMapObject::SetMapSize(int width, int height) { if(width < 0 || height < 0 || (GetMapWidth() == width && GetMapHeight() == height)) //Avoid changing the size if the same return; tileMap.Get().SetSize(width, height); vertexArray = TileMapExtension::GenerateVertexArray(tileSet.Get(), tileMap.Get()); hitboxes = TileMapExtension::GenerateHitboxes(tileSet.Get(), tileMap.Get()); }
Vector2 TileMapInfo2D::ConvertPosition(const Vector2& position) const { switch (orientation_) { case O_ISOMETRIC: { Vector2 index = position * PIXEL_SIZE / tileHeight_; return Vector2((width_ + index.x_ - index.y_) * tileWidth_ * 0.5f, (height_ * 2.0f - index.x_ - index.y_) * tileHeight_ * 0.5f); } case O_STAGGERED: return Vector2(position.x_ * PIXEL_SIZE, GetMapHeight() - position.y_ * PIXEL_SIZE); case O_ORTHOGONAL: default: return Vector2(position.x_ * PIXEL_SIZE, GetMapHeight() - position.y_ * PIXEL_SIZE); } return Vector2::ZERO; }
void display(void) { // clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mat4 total, modelView, camMatrix; printError("pre display"); glUseProgram(program); // Build matrix lookAtPoint = VectorAdd(cam, camDir); camMatrix = lookAt(cam.x, cam.y, cam.z, lookAtPoint.x, lookAtPoint.y, lookAtPoint.z, 0.0, 1.0, 0.0); calculateCullingFrustum(camMatrix); modelView = IdentityMatrix(); total = Mult(camMatrix, modelView); glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_TRUE, total.m); glUniform3f(glGetUniformLocation(program, "camPos"), cam.x, cam.y, cam.z); glBindTexture(GL_TEXTURE_2D, tex1); // Bind Our Texture tex1 DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord"); /* mat4 foobar = Mult(modelView, camMatrix); */ GLfloat ballY = GetMapHeight(tm,ttex.width, ttex.height, ballX, ballZ); if (sphereInFrustum((vec3) {ballX, ballY, ballZ}, 10.0f)) { modelView = T(ballX, ballY, ballZ); total = Mult(camMatrix, modelView); glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_TRUE, total.m); DrawModel(m2, program, "inPosition", "inNormal", "inTexCoord"); printf("foo\n"); } printError("display 2"); glutSwapBuffers(); }