mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 21:03:33 +02:00
Merge pull request #4909 from sethalves/airhockey-hull
airhockey -- use a collision hull for table. make deletion code safer
This commit is contained in:
commit
925ef1d930
2 changed files with 22 additions and 228 deletions
|
@ -17,7 +17,7 @@ var FIELD_LENGTH = 1.92;
|
|||
var FLOOR_THICKNESS = 0.20;
|
||||
var EDGE_THICKESS = 0.10;
|
||||
var EDGE_HEIGHT = 0.10;
|
||||
var DROP_HEIGHT = 0.3;
|
||||
var DROP_HEIGHT = 0.25;
|
||||
var PUCK_SIZE = 0.15;
|
||||
var PUCK_THICKNESS = 0.05;
|
||||
var PADDLE_SIZE = 0.15;
|
||||
|
@ -71,7 +71,16 @@ var edgeRestitution = 0.9;
|
|||
var floorFriction = 0.01;
|
||||
|
||||
var paddle1Pos, paddle2Pos;
|
||||
var names = ['floor', 'table', 'paddle', 'edge', 'puck', 'hockeyLight'];
|
||||
// use some names that wont collide with other content
|
||||
var names = ["air-hockey-table-23j4h1jh82jsjfw91jf232n2k", // keep this synchronized with what's in grabHockey.js
|
||||
"air-hockey-paddle-23j4h1jh82jsjfw91jf232n2k",
|
||||
"air-hockey-puck-23j4h1jh82jsjfw91jf232n2k",
|
||||
"air-hockey-light-23j4h1jh82jsjfw91jf232n2k"];
|
||||
var table_name_index = 0;
|
||||
var paddle_name_index = 1;
|
||||
var puck_name_index = 2;
|
||||
var light_name_index = 3;
|
||||
|
||||
|
||||
var deleteButton = Overlays.addOverlay("image", {
|
||||
x: screenSize.x / 2 - BUTTON_SIZE,
|
||||
|
@ -112,7 +121,7 @@ var paddle1, paddle2;
|
|||
function makeNewProp(which, position) {
|
||||
if (which == "puck") {
|
||||
return Entities.addEntity({
|
||||
name: 'puck',
|
||||
name: names[puck_name_index],
|
||||
type: "Model",
|
||||
modelURL: puckModel,
|
||||
compoundShapeURL: puckCollisionModel,
|
||||
|
@ -150,7 +159,7 @@ function makeNewProp(which, position) {
|
|||
z: FIELD_LENGTH * 0.35
|
||||
});
|
||||
return Entities.addEntity({
|
||||
name: "paddle",
|
||||
name: names[paddle_name_index],
|
||||
type: "Model",
|
||||
modelURL: paddleModel,
|
||||
compoundShapeURL: paddleCollisionModel,
|
||||
|
@ -184,7 +193,7 @@ function makeNewProp(which, position) {
|
|||
z: -FIELD_LENGTH * 0.35
|
||||
});
|
||||
return Entities.addEntity({
|
||||
name: "paddle",
|
||||
name: names[paddle_name_index],
|
||||
type: "Model",
|
||||
modelURL: paddleModel,
|
||||
compoundShapeURL: paddleCollisionModel,
|
||||
|
@ -281,226 +290,11 @@ function mousePressEvent(event) {
|
|||
|
||||
function spawnAllTheThings() {
|
||||
center = Vec3.sum(MyAvatar.position, Vec3.multiply((FIELD_WIDTH + FIELD_LENGTH) * 0.60, Quat.getFront(Camera.getOrientation())));
|
||||
floor = Entities.addEntity({
|
||||
name: "floor",
|
||||
type: "Box",
|
||||
position: Vec3.subtract(center, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}),
|
||||
dimensions: {
|
||||
x: FIELD_WIDTH,
|
||||
y: FLOOR_THICKNESS,
|
||||
z: FIELD_LENGTH
|
||||
},
|
||||
color: {
|
||||
red: 128,
|
||||
green: 128,
|
||||
blue: 128
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
ignoreCollisions: false,
|
||||
locked: true,
|
||||
friction: floorFriction,
|
||||
visible: debugVisible,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
edge1 = Entities.addEntity({
|
||||
name: 'edge',
|
||||
type: "Box",
|
||||
collisionSoundURL: hitSideSound,
|
||||
position: Vec3.sum(center, {
|
||||
x: FIELD_WIDTH / 2.0,
|
||||
y: FLOOR_THICKNESS / 2.0,
|
||||
z: 0
|
||||
}),
|
||||
dimensions: {
|
||||
x: EDGE_THICKESS,
|
||||
y: EDGE_HEIGHT,
|
||||
z: FIELD_LENGTH + EDGE_THICKESS
|
||||
},
|
||||
color: {
|
||||
red: 100,
|
||||
green: 100,
|
||||
blue: 100
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
ignoreCollisions: false,
|
||||
visible: debugVisible,
|
||||
restitution: edgeRestitution,
|
||||
locked: true,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
edge2 = Entities.addEntity({
|
||||
name: 'edge',
|
||||
type: "Box",
|
||||
collisionSoundURL: hitSideSound,
|
||||
position: Vec3.sum(center, {
|
||||
x: -FIELD_WIDTH / 2.0,
|
||||
y: FLOOR_THICKNESS / 2.0,
|
||||
z: 0
|
||||
}),
|
||||
dimensions: {
|
||||
x: EDGE_THICKESS,
|
||||
y: EDGE_HEIGHT,
|
||||
z: FIELD_LENGTH + EDGE_THICKESS
|
||||
},
|
||||
color: {
|
||||
red: 100,
|
||||
green: 100,
|
||||
blue: 100
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
ignoreCollisions: false,
|
||||
visible: debugVisible,
|
||||
restitution: edgeRestitution,
|
||||
locked: true,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
edge3a = Entities.addEntity({
|
||||
name: 'edge',
|
||||
type: "Box",
|
||||
collisionSoundURL: hitSideSound,
|
||||
position: Vec3.sum(center, {
|
||||
x: FIELD_WIDTH / 4.0 + (GOAL_WIDTH / 4.0),
|
||||
y: FLOOR_THICKNESS / 2.0,
|
||||
z: -FIELD_LENGTH / 2.0
|
||||
}),
|
||||
dimensions: {
|
||||
x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0,
|
||||
y: EDGE_HEIGHT,
|
||||
z: EDGE_THICKESS
|
||||
},
|
||||
color: {
|
||||
red: 100,
|
||||
green: 100,
|
||||
blue: 100
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
ignoreCollisions: false,
|
||||
visible: debugVisible,
|
||||
restitution: edgeRestitution,
|
||||
locked: true,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
edge3b = Entities.addEntity({
|
||||
name: 'edge',
|
||||
type: "Box",
|
||||
collisionSoundURL: hitSideSound,
|
||||
position: Vec3.sum(center, {
|
||||
x: -FIELD_WIDTH / 4.0 - (GOAL_WIDTH / 4.0),
|
||||
y: FLOOR_THICKNESS / 2.0,
|
||||
z: -FIELD_LENGTH / 2.0
|
||||
}),
|
||||
dimensions: {
|
||||
x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0,
|
||||
y: EDGE_HEIGHT,
|
||||
z: EDGE_THICKESS
|
||||
},
|
||||
color: {
|
||||
red: 100,
|
||||
green: 100,
|
||||
blue: 100
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
ignoreCollisions: false,
|
||||
visible: debugVisible,
|
||||
restitution: edgeRestitution,
|
||||
locked: true,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
edge4a = Entities.addEntity({
|
||||
name: 'edge',
|
||||
type: "Box",
|
||||
collisionSoundURL: hitSideSound,
|
||||
position: Vec3.sum(center, {
|
||||
x: FIELD_WIDTH / 4.0 + (GOAL_WIDTH / 4.0),
|
||||
y: FLOOR_THICKNESS / 2.0,
|
||||
z: FIELD_LENGTH / 2.0
|
||||
}),
|
||||
dimensions: {
|
||||
x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0,
|
||||
y: EDGE_HEIGHT,
|
||||
z: EDGE_THICKESS
|
||||
},
|
||||
color: {
|
||||
red: 100,
|
||||
green: 100,
|
||||
blue: 100
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
ignoreCollisions: false,
|
||||
visible: debugVisible,
|
||||
restitution: edgeRestitution,
|
||||
locked: true,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
edge4b = Entities.addEntity({
|
||||
name: 'edge',
|
||||
type: "Box",
|
||||
collisionSoundURL: hitSideSound,
|
||||
position: Vec3.sum(center, {
|
||||
x: -FIELD_WIDTH / 4.0 - (GOAL_WIDTH / 4.0),
|
||||
y: FLOOR_THICKNESS / 2.0,
|
||||
z: FIELD_LENGTH / 2.0
|
||||
}),
|
||||
dimensions: {
|
||||
x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0,
|
||||
y: EDGE_HEIGHT,
|
||||
z: EDGE_THICKESS
|
||||
},
|
||||
color: {
|
||||
red: 100,
|
||||
green: 100,
|
||||
blue: 100
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
ignoreCollisions: false,
|
||||
visible: debugVisible,
|
||||
restitution: edgeRestitution,
|
||||
locked: true,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
table = Entities.addEntity({
|
||||
name: "table",
|
||||
name: names[table_name_index],
|
||||
type: "Model",
|
||||
modelURL: polyTable,
|
||||
compoundShapeURL: "http://headache.hungry.com/~seth/hifi/airhockey-table-hull.obj",
|
||||
dimensions: Vec3.multiply({
|
||||
x: 0.8,
|
||||
y: 0.45,
|
||||
|
@ -514,7 +308,7 @@ function spawnAllTheThings() {
|
|||
});
|
||||
|
||||
light = Entities.addEntity({
|
||||
name: "hockeyLight",
|
||||
name: names[light_name_index],
|
||||
type: "Light",
|
||||
dimensions: {
|
||||
x: 5,
|
||||
|
@ -540,14 +334,13 @@ function spawnAllTheThings() {
|
|||
|
||||
function deleteAllTheThings() {
|
||||
|
||||
Script.update.disconnect(update);
|
||||
//delete all nearby entitites that are named any the names from our names array
|
||||
var nearbyEntities = Entities.findEntities(MyAvatar.position, ENTITY_SEARCH_RANGE);
|
||||
for (var i = 0; i < nearbyEntities.length; i++) {
|
||||
var entityName = Entities.getEntityProperties(nearbyEntities[i]).name;
|
||||
for (var j = 0; j < names.length; j++) {
|
||||
if (names[j] === entityName) {
|
||||
//We have a mach- delete this entity
|
||||
//We have a match - delete this entity
|
||||
Entities.editEntity(nearbyEntities[i], {
|
||||
locked: false
|
||||
});
|
||||
|
@ -556,7 +349,7 @@ function deleteAllTheThings() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Script.update.disconnect(update);
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
|
@ -607,4 +400,4 @@ function scriptEnding() {
|
|||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
|
|
@ -144,7 +144,8 @@ function mousePressEvent(event) {
|
|||
var potentialTables = Entities.findEntities(MyAvatar.position, TABLE_SEARCH_RANGE);
|
||||
potentialTables.forEach(function(table) {
|
||||
var props = Entities.getEntityProperties(table);
|
||||
if (props.name === "table") {
|
||||
// keep this name synchronized with what's in airHockey.js
|
||||
if (props.name === "air-hockey-table-23j4h1jh82jsjfw91jf232n2k") {
|
||||
var tablePosition = props.position;
|
||||
// when we know the table's position we can compute the X-Z bounds of its field
|
||||
fieldMax = Vec3.sum(tablePosition, fieldMaxOffset);
|
||||
|
|
Loading…
Reference in a new issue