mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 12:53:03 +02:00
use a collision hull for table. make deletion code safer
This commit is contained in:
parent
1f8008e5b5
commit
5ea506f2c1
1 changed files with 19 additions and 226 deletions
|
@ -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",
|
||||
"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);
|
||||
|
|
Loading…
Reference in a new issue