public ResetCameraAction(ICamera c) { camera = c; upAxis = camera.getUpAxis(); rightAxis = camera.getRightAxis(); viewAxis = camera.getViewDirection(); location = camera.getLocation(); }
public void initGame() { try { this.gameClient = new GameClient(InetAddress.getByName(serverAddr), serverPort, serverProtocol, this); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (gameClient != null) { gameClient.sendJoinMessage(); } display = getDisplaySystem(); eventMgr = EventManager.getInstance(); display.setTitle("Super Duper Gem Collector X"); renderer = getDisplaySystem().getRenderer(); if (scriptCheck) { initPhysics(); initSkyBox(); initTerrain(); initGameObjects(); initPlayers(); initScript(); initInput(); initEvents(); initAudio(); } else { initPhysics(); initSkyBox(); initTerrain(); initGameObjects(); initPlayers(); initWorldAxis(); initInput(); initEvents(); initAudio(); } // HUD player1ScoreString = new HUDString("Score= " + player1Score); player1ScoreString.setLocation(0.9, 0.05); player1ScoreString.setColor(Color.GREEN); camera1.addToHUD(player1ScoreString); player1HPString = new HUDString("HP: " + player1HP); camera1.addToHUD(player1HPString); player1GameOverString = new HUDString(""); player1GameOverString.setLocation(.5, .5); camera1.addToHUD(player1GameOverString); }
private void initPlayers() { File file = new File(File.pathSeparator); System.out.println(file.getAbsolutePath()); OgreXMLParser loader = new OgreXMLParser(); try { model = loader.loadModel( "src/animated_objects/Cube.mesh.xml", "src/animated_objects/chicken.material", "src/animated_objects/Cube.skeleton.xml"); model.updateGeometricState(0, true); java.util.Iterator<SceneNode> modelIterator = model.iterator(); player1 = (Model3DTriMesh) modelIterator.next(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } Texture chickenTexture = TextureManager.loadTexture2D("src/animated_objects/green_chicken.jpg"); chickenTexture.setApplyMode(sage.texture.Texture.ApplyMode.Replace); chickenTextureState = (TextureState) display.getRenderer().createRenderState(RenderState.RenderStateType.Texture); chickenTextureState.setTexture(chickenTexture, 0); chickenTextureState.setEnabled(true); player1.setRenderState(chickenTextureState); player1.updateRenderStates(); player = physicsEngine.addSphereObject( physicsEngine.nextUID(), ballMass, player1.getWorldTransform().getValues(), 1.0f); player.setBounciness(0.0f); player1.setPhysicsObject(player); player1.scale(.35f, .35f, .35f); addGameWorldObject(player1); // player1.translate(133f, 13f, 123f); playerInitM = new Matrix3D(); playerInitM.concatenate((Matrix3D) player1.getLocalTranslation().clone()); playerInitM.concatenate((Matrix3D) player1.getLocalRotation().clone()); playerInitM.concatenate((Matrix3D) player1.getLocalScale().clone()); camera1 = new JOGLCamera(renderer); camera1.setPerspectiveFrustum(60, 1, 1, 1000); camera1.setViewport(0.0, 1.0, 0.0, 1); }
public void setEarParameters() { Matrix3D avDir = (Matrix3D) (player1.getWorldRotation().clone()); float camAz; if (!isGPOn) { camAz = cam1Controller.getAzimuth(); } else { camAz = cam1GPController.getAzimuth(); } avDir.rotateY(180.0f - camAz); Vector3D camDir = new Vector3D(0, 0, 1); camDir = camDir.mult(avDir); audioMgr.getEar().setLocation(camera1.getLocation()); audioMgr.getEar().setOrientation(camDir, new Vector3D(0, 1, 0)); }
public void update(float elapsedTimeMS) { super.update(elapsedTimeMS); player1.updateAnimation(elapsedTimeMS); if (!isGPOn) { cam1Controller.update(elapsedTimeMS); } else { cam1GPController.update(elapsedTimeMS); } if (gameClient != null) { gameClient.sendUpdate(getPlayerPosition()); gameClient.processPackets(); } physicsEngine.update(20.0f); Matrix3D mat; Vector3D translateVec; for (SceneNode s : getGameWorld()) { if (s.getPhysicsObject() != null) { if (s.getWorldBound().intersects(player1.getWorldBound()) && (s.getName().equals("src/Models/car.obj") || s.getName().equals("src/Models/truck.obj"))) { playerHit = true; s.setLocalTranslation(new Matrix3D()); s.translate(0, 10, 0); } if (s.getName().equals(player1.getName())) { mat = s.getLocalTranslation(); translateVec = mat.getCol(3); s.getLocalTranslation().setCol(3, translateVec); } else { mat = new Matrix3D(s.getPhysicsObject().getTransform()); translateVec = mat.getCol(3); s.getLocalTranslation().setCol(3, translateVec); } } else if (s instanceof TriMesh && s.getWorldBound().intersects(player1.getWorldBound()) && (s.getName().equals("src/Models/car.obj") || s.getName().equals("src/Models/truck.obj"))) { playerHit = true; } } player1ScoreString.setText("Score = " + player1Score); player1HPString.setText("HP: " + player1HP); Matrix3D camTranslation = new Matrix3D(); camTranslation.translate( camera1.getLocation().getX(), camera1.getLocation().getY(), camera1.getLocation().getZ()); skybox.setLocalTranslation(camTranslation); if (playerHit) { splatSound.play(100, false); player1.translate(133f, 13f, 123f); playerHit = false; } if (gameOver) { player1GameOverString.setText("LOOOOOOOSER!"); } else if (!player1Won) { if (checkWin()) { gameClient.sendWonMessage(); player1Won = true; player1GameOverString.setText("WINNER!"); } } }
@Override public void performAction(float arg0, Event arg1) { camera.setLocation(location); camera.setAxes(rightAxis, upAxis, viewAxis); }