Skip to content

Commit

Permalink
Updated this to the new ammo.js version.
Browse files Browse the repository at this point in the history
  • Loading branch information
BunZaga committed Nov 30, 2013
1 parent 575eb88 commit b412030
Show file tree
Hide file tree
Showing 82 changed files with 25,571 additions and 23,355 deletions.
68 changes: 34 additions & 34 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,59 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>NavMesh V2 | Goo Engine</title>
<title>Zombie shooter WIP | Goo Engine</title>

<meta property="og:title" content="NavMesh V2"/>
<meta property="og:url" content="http://published.gooengine.com.s3-website-eu-west-1.amazonaws.com/JDLFFKOBQY6UnUP0Re4zCQ/"/>
<meta property="og:updated_time" content="2013-11-16T01:20:01.661486"/>
<meta property="og:title" content="Boiler Plate"/>
<meta property="og:url" content="/"/>
<meta property="og:updated_time" content="2013-11-26T05:25:19.501224"/>
<meta property="og:site_name" content="Goo Create"/>
<meta property="og:type" content="website"/>

<script src="lib/howler.min.js"></script>
<script src="lib/Tween.js"></script>
<script src="lib/hammer.js"></script>
<script src="lib/ammo.js"></script>
<script src="lib/goo-require.js"></script>
<script src="js/loadScene.js"></script>
<script src="js/sphereTriangleTest.js"></script>
<style>
body {
background: black;
}

#goo {
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
right: 0px;
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
right: 0px;
width: 100%;
height: 100%;
}
#loading {
position: absolute;
top: 50%;
left: 50%;
width: 100px;
height: 30px;
line-height: 30px;
font-size: 16px;
font-family: Helvetica, Arial;
color: white;
margin-left: -50px;
margin-top: -15px;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
width: 100px;
height: 30px;
line-height: 30px;
font-size: 16px;
font-family: Helvetica, Arial;
color: white;
margin-left: -50px;
margin-top: -15px;
text-align: center;
}
#crosshair {
position: absolute;
z-index: 21;
left: 50%;
top: 50%;
margin-left: -8px;
margin-top: -5px;
user-select: none;
position: absolute;
z-index: 21;
left: 50%;
top: 50%;
margin-left: -8px;
margin-top: -5px;
user-select: none;
}
</style>
</head>
<body>
<div id="loading">Loading...</div>
<div id="crosshair" ondragstart="return false;" onselectstart="return false;">+</div>
</body>
</html>
</html>
File renamed without changes.
218 changes: 218 additions & 0 deletions js/FPSCamComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
define([
'goo/entities/components/Component',
'goo/math/Vector3',
'goo/util/GameUtils',
'js/Input',
'js/Game',
'js/Time',
'goo/math/Ray',
'goo/renderer/Camera',
'goo/entities/components/CameraComponent',
'goo/entities/EntityUtils',
'js/sphereMovement'
], function(
Component,
Vector3,
GameUtils,
Input,
Game,
Time,
Ray,
Camera,
CameraComponent,
EntityUtils,
SphereMovement
) {
'use strict';
function FPSCamComponent(userEntity){
this.type = "FPSCamComponent";

this.ray = new Ray();
//var room = -1;

this.speed = 5;
//this.fwdBase = new Vector3(-1,0,0);
//this.leftBase = new Vector3(0,0,1);
this.fwdBase = new Vector3(0,0,-1);
this.leftBase = new Vector3(-1,0,0);

this.direction = new Vector3(0,0,1);
this.left = new Vector3(1,0,0);
this.movement = new Vector3(1,0,0);
this.grounded = false;
//var wantY = 0.0;
//var gravity = 20;

this.oldPos = new Vector3();
this.newPos = new Vector3();
this.oldVelocity = new Vector3();
this.oldYaw = 0;
this.newYaw = 0;
this.radRot = 0.0;
this.oldPitch = 0;
this.newPitch = 0;

this.torqueVector = new Ammo.btVector3(0, 0, 0);
this.ammoComponent = userEntity.ammoComponent;
// this.sphereMovement = new SphereMovement();

this.moveEntity = userEntity;
this.moveTransform = userEntity.transformComponent.transform;

this.cam = EntityUtils.createTypicalEntity(Game.goo.world, new Camera(45, 1.0, 0.01, 130));
Game.viewCam = this.cam;
this.camTransform = this.cam.transformComponent.transform;
this.cam.addToWorld();

this.moveEntity.transformComponent.attachChild(this.cam.transformComponent);
this.moveEntity.transformComponent.setUpdated();
Game.register("MouseMove", this, mouseMove);
Game.register("MouseButton1", this, mouseDown1);
Game.register("FixedUpdate", this, fixedUpdate);
Game.register("Update", this, update);
Game.register("RenderUpdate", this, renderUpdate);
};

FPSCamComponent.prototype = Object.create(Component.prototype);
FPSCamComponent.prototype.setHeight = function(n0){
this.cam.transformComponent.transform.translation.y = n0;
this.cam.transformComponent.setUpdated();
};

function mouseMove() {
if(!document.pointerLockElement){return;}

this.newPitch = this.oldPitch - Input.movement.y * 0.005;

if(this.newPitch > Math.PI*0.5){
this.newPitch = Math.PI*0.5;
}
if(this.newPitch < -Math.PI*0.5){
this.newPitch = -Math.PI*0.5;
}

this.newYaw = this.oldYaw - Input.movement.x * 0.005;
this.radRot = this.newYaw * (Math.PI/180);
};

function mouseDown1(t) {
if(true == t){
if(!document.pointerLockElement) {
GameUtils.requestPointerLock();
}
}
};

function update(){
//console.log(this.newPos.x+","+this.newPos.z);
//if(this.room != Game.userEntity.room){
// if(this.room != -1){
// console.log("userEntity was in "+Game.userEntity.room+" now it is in "+room);
// Game.raiseEvent("PlayerMoved", this.room, this.sphereTransform.translation);
// Game.userEntity.room = this.room;
// }
//}
}
var calcVec = new Vector3();
function fixedUpdate(){
// console.log("Walk the sphere: ", this.sphereEntity)
var self = this;
this.grounded = false;
this.oldYaw = this.newYaw;
this.oldPitch = this.newPitch;
this.oldPos.copy(this.newPos);

//zombieTransform.transform.translation.set(physTransform.transform.translation);
//zombieTransform.setUpdated();

this.moveTransform.applyForwardVector( this.fwdBase, this.direction); // get the direction the camera is looking
this.moveTransform.applyForwardVector( this.leftBase, this.left); // get the direction to the left of the camera

this.movement.copy(Vector3.ZERO);

if (true == Input.keys[87]) // W
this.movement.add(this.direction);
if (true == Input.keys[83]) // S
this.movement.sub(this.direction);
if (true == Input.keys[65]) // A
this.movement.add(this.left);
if (true == Input.keys[68]) // D
this.movement.sub(this.left);

this.movement.normalize(); // move the same amount regardless of where we look-

this.movement.y = this.ammoComponent.getLinearVelocity().y();
this.ray.origin.copy(this.newPos);
this.ray.origin.y += 1.0;
this.ray.direction = Vector3.DOWN;
Game.castRay(this.ray, function(hit){
if(null != hit){
//console.log(hit.entity.name);
//console.log(hit.distance);
if(hit.distance <= 1.9001){
self.grounded = true;
}
}
}, 1);
if (true == Input.keys[32] && true == this.grounded) { // space bar
// (2 * gravity * height)*mass
this.movement.y = Math.sqrt(2*12*1.0)*1.5;
}

//this.applyMovementState(this.selectMovementState());
// this.sphereMovement.applyForward(this.movement.z * this.speed * Math.cos(this.sphereMovement.controlState.yaw * (Math.PI/180)));
// this.sphereMovement.applyStrafe(this.movement.x * this.speed * Math.sin(this.sphereMovement.controlState.yaw * (Math.PI/180)));

// this.sphereMovement.updateTargetVectors();
// var targetVelocity = this.sphereMovement.getTargetVelocity();
// This torqueVector currently applies arbitrary directional rotation to the sphere. This needs
// to know the orientation of the gamepiece to roll it in the correct direction.

this.torqueVector.setValue(
this.movement.x * this.speed,
this.movement.y,
this.movement.z * this.speed);

this.ammoComponent.setLinearVelocity(this.torqueVector);

//this.torqueVector.setValue(0,0,0);
//this.ammoComponent.setAngularVelocity(this.torqueVector);

//this.torqueVector.setValue(targetVelocity.data[0], targetVelocity.data[1], targetVelocity.data[2]);

//this.ammoComponent.clearForces();
//this.ammoComponent.applyTorqueImpulse(this.torqueVector);

//if(targetVelocity.data[1] != 0) {
// this.torqueVector.setValue(0, targetVelocity.data[1], 0);
// this.ammoComponent.applyCentralImpulse(this.torqueVector)
//}
//this.ammoComponent.activate();
this.ammoComponent.getMotionState().getWorldTransform(Game.physTransform);
var origin = Game.physTransform.getOrigin();
this.newPos.x = origin.x();
this.newPos.y = origin.y();
this.newPos.z = origin.z();
};

function renderUpdate(){
this.camTransform.rotation.fromAngles(
(Time.alpha * this.newPitch) + (this.oldPitch * (1-Time.alpha)),
0,
0);
this.cam.transformComponent.setUpdated();

this.moveTransform.rotation.fromAngles(
0,
(Time.alpha * this.newYaw) + (this.oldYaw * (1-Time.alpha)),
0);

this.moveEntity.transformComponent.setTranslation(
(Time.alpha * this.newPos.x) + (this.oldPos.x * (1-Time.alpha)),
(Time.alpha * this.newPos.y) + (this.oldPos.y * (1-Time.alpha)),
(Time.alpha * this.newPos.z) + (this.oldPos.z * (1-Time.alpha)));
this.moveEntity.transformComponent.setUpdated();
};

return FPSCamComponent;
});
29 changes: 29 additions & 0 deletions js/FlashlightComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
define([
'goo/entities/components/Component',
'goo/entities/components/LightComponent',
'goo/renderer/light/SpotLight',
'js/Game'
], function(
Component,
LightComponent,
SpotLight,
Game
) {
'use strict';
function FlashlightComponent(){
this.type = "FlashlightComponent";
var spotLight = new SpotLight();
spotLight.angle = 25;
//spotLight.range = 10;
spotLight.penumbra = 5;
spotLight.intensity = 1;

var spotLightEntity = Game.goo.world.createEntity('FlashLight');
spotLightEntity.setComponent(new LightComponent(spotLight));
spotLightEntity.addToWorld();

Game.viewCam.transformComponent.attachChild( spotLightEntity.transformComponent);
}
FlashlightComponent.prototype = Object.create(Component.prototype);
return FlashlightComponent;
});
Loading

0 comments on commit b412030

Please sign in to comment.