static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; case 'z': /* move to the left */ stepCamera(-0.15f); break; case 'x': /* move to the right */ stepCamera(0.15f); break; } }
void step() { stepCamera(); physics.projectPositions(); for(int i=0; i<CONSTRAINT_ITERATIONS; ++i) { physics.applyVoxelGridConstraint(&voxelGrid); physics.applyConstraints(); } physics.unprojectVelocities(); physics.removeFlagged(); if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && placeTimer < 0) { glm::vec3 direction = camera.getDirection(); glm::ivec3 result; glBindTexture(GL_TEXTURE_2D, circleTexture); glm::ivec3 result_face; float d = voxelGrid.intersectRay(camera.position, direction, result, result_face); if(d > 0.0f) { placeTimer = 10; voxelGrid.set(result+result_face, 1); } } placeTimer--; if(sf::Mouse::isButtonPressed(sf::Mouse::Right) && fireTimer < 0) { physics.add(new Particle(camera.position-glm::vec3(0.0f,0.05f,0.0f), camera.getDirection() * 5.5f, 1.0f, 0.05f, PARTICLE_PROJECTILE)); fireTimer = 3; } fireTimer--; }