mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:37:58 +02:00
added spawner script for spray paint toy
This commit is contained in:
parent
878d42a8d0
commit
f48cfa1208
1 changed files with 74 additions and 0 deletions
74
examples/sprayPaintSpawner.js
Normal file
74
examples/sprayPaintSpawner.js
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
// sprayPaintSpawner.js
|
||||||
|
//
|
||||||
|
// Created by Eric Levin on 9/3/15
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// This is script spwans a spreay paint can model with the sprayPaintCan.js entity script attached
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
|
var scriptURL = "entityScripts/sprayPaintCan.js";
|
||||||
|
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
|
||||||
|
|
||||||
|
var paintGun = Entities.addEntity({
|
||||||
|
type: "Model",
|
||||||
|
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/sprayGun.fbx?=v4",
|
||||||
|
position: center,
|
||||||
|
dimensions: {
|
||||||
|
x: 0.03,
|
||||||
|
y: 0.15,
|
||||||
|
z: 0.34
|
||||||
|
},
|
||||||
|
collisionsWillMove: true,
|
||||||
|
shapeType: 'box',
|
||||||
|
script: scriptURL
|
||||||
|
});
|
||||||
|
|
||||||
|
var whiteboard = Entities.addEntity({
|
||||||
|
type: "Box",
|
||||||
|
position: center,
|
||||||
|
dimensions: {
|
||||||
|
x: 2,
|
||||||
|
y: 1.5,
|
||||||
|
z: .01
|
||||||
|
},
|
||||||
|
rotation: orientationOf(Vec3.subtract(MyAvatar.position, center)),
|
||||||
|
color: {
|
||||||
|
red: 250,
|
||||||
|
green: 250,
|
||||||
|
blue: 250
|
||||||
|
},
|
||||||
|
// visible: false
|
||||||
|
});
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
Entities.deleteEntity(paintGun);
|
||||||
|
Entities.deleteEntity(whiteboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(cleanup);
|
||||||
|
|
||||||
|
|
||||||
|
function orientationOf(vector) {
|
||||||
|
var Y_AXIS = {
|
||||||
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
var X_AXIS = {
|
||||||
|
x: 1,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
var theta = 0.0;
|
||||||
|
|
||||||
|
var RAD_TO_DEG = 180.0 / Math.PI;
|
||||||
|
var direction, yaw, pitch;
|
||||||
|
direction = Vec3.normalize(vector);
|
||||||
|
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
|
||||||
|
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
|
||||||
|
return Quat.multiply(yaw, pitch);
|
||||||
|
}
|
Loading…
Reference in a new issue