mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 22:16:39 +02:00
Fix paddleBall.js
This commit is contained in:
parent
103fe3c545
commit
ae2f7f6ff6
1 changed files with 12 additions and 12 deletions
|
@ -32,14 +32,14 @@ var SPRING_FORCE = 15.0;
|
||||||
var lastSoundTime = 0;
|
var lastSoundTime = 0;
|
||||||
var gameOn = false;
|
var gameOn = false;
|
||||||
var leftHanded = true;
|
var leftHanded = true;
|
||||||
var controllerID;
|
var hand;
|
||||||
|
|
||||||
|
|
||||||
function setControllerID() {
|
function setControllerID() {
|
||||||
if (leftHanded) {
|
if (leftHanded) {
|
||||||
controllerID = 1;
|
hand = Controller.Standard.LeftHand;
|
||||||
} else {
|
} else {
|
||||||
controllerID = 3;
|
hand = Controller.Standard.RightHand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ var ball, paddle, paddleModel, line;
|
||||||
function createEntities() {
|
function createEntities() {
|
||||||
ball = Entities.addEntity(
|
ball = Entities.addEntity(
|
||||||
{ type: "Sphere",
|
{ type: "Sphere",
|
||||||
position: Controller.getSpatialControlPosition(controllerID),
|
position: Controller.getPoseValue(hand).translation,
|
||||||
dimensions: { x: BALL_SIZE, y: BALL_SIZE, z: BALL_SIZE },
|
dimensions: { x: BALL_SIZE, y: BALL_SIZE, z: BALL_SIZE },
|
||||||
color: BALL_COLOR,
|
color: BALL_COLOR,
|
||||||
gravity: { x: 0, y: GRAVITY, z: 0 },
|
gravity: { x: 0, y: GRAVITY, z: 0 },
|
||||||
|
@ -73,27 +73,27 @@ function createEntities() {
|
||||||
|
|
||||||
paddle = Entities.addEntity(
|
paddle = Entities.addEntity(
|
||||||
{ type: "Box",
|
{ type: "Box",
|
||||||
position: Controller.getSpatialControlPosition(controllerID),
|
position: Controller.getPoseValue(hand).translation,
|
||||||
dimensions: { x: PADDLE_SIZE, y: PADDLE_THICKNESS, z: PADDLE_SIZE * 0.80 },
|
dimensions: { x: PADDLE_SIZE, y: PADDLE_THICKNESS, z: PADDLE_SIZE * 0.80 },
|
||||||
color: PADDLE_COLOR,
|
color: PADDLE_COLOR,
|
||||||
gravity: { x: 0, y: 0, z: 0 },
|
gravity: { x: 0, y: 0, z: 0 },
|
||||||
ignoreCollisions: false,
|
ignoreCollisions: false,
|
||||||
damping: 0.10,
|
damping: 0.10,
|
||||||
visible: false,
|
visible: false,
|
||||||
rotation: Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(controllerID)),
|
rotation: Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(hand).rotation,
|
||||||
collisionsWillMove: false });
|
collisionsWillMove: false });
|
||||||
|
|
||||||
modelURL = "http://public.highfidelity.io/models/attachments/pong_paddle.fbx";
|
modelURL = "http://public.highfidelity.io/models/attachments/pong_paddle.fbx";
|
||||||
paddleModel = Entities.addEntity(
|
paddleModel = Entities.addEntity(
|
||||||
{ type: "Model",
|
{ type: "Model",
|
||||||
position: Vec3.sum(Controller.getSpatialControlPosition(controllerID), PADDLE_BOX_OFFSET),
|
position: Vec3.sum(Controller.getPoseValue(hand).translation, PADDLE_BOX_OFFSET),
|
||||||
dimensions: { x: PADDLE_SIZE * 1.5, y: PADDLE_THICKNESS, z: PADDLE_SIZE * 1.25 },
|
dimensions: { x: PADDLE_SIZE * 1.5, y: PADDLE_THICKNESS, z: PADDLE_SIZE * 1.25 },
|
||||||
color: PADDLE_COLOR,
|
color: PADDLE_COLOR,
|
||||||
gravity: { x: 0, y: 0, z: 0 },
|
gravity: { x: 0, y: 0, z: 0 },
|
||||||
ignoreCollisions: true,
|
ignoreCollisions: true,
|
||||||
modelURL: modelURL,
|
modelURL: modelURL,
|
||||||
damping: 0.10,
|
damping: 0.10,
|
||||||
rotation: Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(controllerID)),
|
rotation: Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(hand).rotation,
|
||||||
collisionsWillMove: false });
|
collisionsWillMove: false });
|
||||||
|
|
||||||
line = Overlays.addOverlay("line3d", {
|
line = Overlays.addOverlay("line3d", {
|
||||||
|
@ -118,7 +118,7 @@ function deleteEntities() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(deltaTime) {
|
function update(deltaTime) {
|
||||||
var palmPosition = Controller.getSpatialControlPosition(controllerID);
|
var palmPosition = Controller.getPoseValue(hand).translation;
|
||||||
var controllerActive = (Vec3.length(palmPosition) > 0);
|
var controllerActive = (Vec3.length(palmPosition) > 0);
|
||||||
|
|
||||||
if (!gameOn && controllerActive) {
|
if (!gameOn && controllerActive) {
|
||||||
|
@ -133,7 +133,7 @@ function update(deltaTime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var paddleOrientation = leftHanded ? PADDLE_ORIENTATION : Quat.multiply(PADDLE_ORIENTATION, Quat.fromPitchYawRollDegrees(0, 180, 0));
|
var paddleOrientation = leftHanded ? PADDLE_ORIENTATION : Quat.multiply(PADDLE_ORIENTATION, Quat.fromPitchYawRollDegrees(0, 180, 0));
|
||||||
var paddleWorldOrientation = Quat.multiply(Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(controllerID)), paddleOrientation);
|
var paddleWorldOrientation = Quat.multiply(Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(hand).rotation), paddleOrientation);
|
||||||
var holdPosition = Vec3.sum(leftHanded ? MyAvatar.getLeftPalmPosition() : MyAvatar.getRightPalmPosition(),
|
var holdPosition = Vec3.sum(leftHanded ? MyAvatar.getLeftPalmPosition() : MyAvatar.getRightPalmPosition(),
|
||||||
Vec3.multiplyQbyV(paddleWorldOrientation, leftHanded ? HOLD_POSITION_LEFT_OFFSET : HOLD_POSITION_RIGHT_OFFSET ));
|
Vec3.multiplyQbyV(paddleWorldOrientation, leftHanded ? HOLD_POSITION_LEFT_OFFSET : HOLD_POSITION_RIGHT_OFFSET ));
|
||||||
|
|
||||||
|
@ -146,10 +146,10 @@ function update(deltaTime) {
|
||||||
Entities.editEntity(ball, { velocity: ballVelocity });
|
Entities.editEntity(ball, { velocity: ballVelocity });
|
||||||
Overlays.editOverlay(line, { start: props.position, end: holdPosition });
|
Overlays.editOverlay(line, { start: props.position, end: holdPosition });
|
||||||
Entities.editEntity(paddle, { position: holdPosition,
|
Entities.editEntity(paddle, { position: holdPosition,
|
||||||
velocity: Controller.getSpatialControlVelocity(controllerID),
|
velocity: Controller.getPoseValue(hand).velocity,
|
||||||
rotation: paddleWorldOrientation });
|
rotation: paddleWorldOrientation });
|
||||||
Entities.editEntity(paddleModel, { position: Vec3.sum(holdPosition, Vec3.multiplyQbyV(paddleWorldOrientation, PADDLE_BOX_OFFSET)),
|
Entities.editEntity(paddleModel, { position: Vec3.sum(holdPosition, Vec3.multiplyQbyV(paddleWorldOrientation, PADDLE_BOX_OFFSET)),
|
||||||
velocity: Controller.getSpatialControlVelocity(controllerID),
|
velocity: Controller.getPoseValue(hand).velocity,
|
||||||
rotation: paddleWorldOrientation });
|
rotation: paddleWorldOrientation });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue