mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Merge pull request #3395 from PhilipRosedale/master
Updated move and butterfly scripts, entity renderer uses glutCube to temporarily fix crash
This commit is contained in:
commit
f33bd82ed8
3 changed files with 85 additions and 30 deletions
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// butterflyFlockTest1.js
|
||||
// butterflies.js
|
||||
//
|
||||
//
|
||||
// Created by Adrian McCarlie on August 2, 2014
|
||||
|
@ -23,9 +23,6 @@ function vScalarMult(v, s) {
|
|||
return rval;
|
||||
}
|
||||
|
||||
function printVector(v) {
|
||||
print(v.x + ", " + v.y + ", " + v.z + "\n");
|
||||
}
|
||||
// Create a random vector with individual lengths between a,b
|
||||
function randVector(a, b) {
|
||||
var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) };
|
||||
|
@ -40,7 +37,7 @@ function vInterpolate(a, b, fraction) {
|
|||
|
||||
var startTimeInSeconds = new Date().getTime() / 1000;
|
||||
|
||||
var lifeTime = 60; // lifetime of the butterflies in seconds!
|
||||
var lifeTime = 600; // lifetime of the butterflies in seconds
|
||||
var range = 1.0; // Over what distance in meters do you want the flock to fly around
|
||||
var frame = 0;
|
||||
|
||||
|
@ -49,7 +46,7 @@ var BUTTERFLY_GRAVITY = 0;//-0.06;
|
|||
var BUTTERFLY_FLAP_SPEED = 1.0;
|
||||
var BUTTERFLY_VELOCITY = 0.55;
|
||||
var DISTANCE_IN_FRONT_OF_ME = 1.5;
|
||||
var DISTANCE_ABOVE_ME = 1.5;
|
||||
var DISTANCE_ABOVE_ME = 1.0;
|
||||
var flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME),
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)));
|
||||
|
@ -81,18 +78,7 @@ function addButterfly() {
|
|||
var color = { red: 100, green: 100, blue: 100 };
|
||||
var size = 0;
|
||||
|
||||
var which = Math.random();
|
||||
if (which < 0.2) {
|
||||
size = 0.08;
|
||||
} else if (which < 0.4) {
|
||||
size = 0.09;
|
||||
} else if (which < 0.6) {
|
||||
size = 0.8;
|
||||
} else if (which < 0.8) {
|
||||
size = 0.8;
|
||||
} else {
|
||||
size = 0.8;
|
||||
}
|
||||
size = 0.06 + Math.random() * 0.2;
|
||||
|
||||
flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME),
|
||||
|
@ -212,7 +198,7 @@ function updateButterflies(deltaTime) {
|
|||
var desiredVelocity = Vec3.subtract(butterflies[i].targetPosition, properties.position);
|
||||
desiredVelocity = vScalarMult(Vec3.normalize(desiredVelocity), BUTTERFLY_VELOCITY);
|
||||
|
||||
properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.2);
|
||||
properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.5);
|
||||
properties.velocity.y = holding ;
|
||||
|
||||
|
||||
|
@ -238,4 +224,11 @@ function updateButterflies(deltaTime) {
|
|||
}
|
||||
|
||||
// register the call back so it fires before each data send
|
||||
Script.update.connect(updateButterflies);
|
||||
Script.update.connect(updateButterflies);
|
||||
|
||||
// Delete our little friends if script is stopped
|
||||
Script.scriptEnding.connect(function() {
|
||||
for (var i = 0; i < numButterflies; i++) {
|
||||
Entities.deleteEntity(butterflies[i].entityID);
|
||||
}
|
||||
});
|
|
@ -20,41 +20,103 @@ var HEAD_MOVE_DEAD_ZONE = 0.0;
|
|||
var HEAD_STRAFE_DEAD_ZONE = 0.0;
|
||||
var HEAD_ROTATE_DEAD_ZONE = 0.0;
|
||||
var HEAD_THRUST_FWD_SCALE = 12000.0;
|
||||
var HEAD_THRUST_STRAFE_SCALE = 1000.0;
|
||||
var HEAD_YAW_RATE = 2.0;
|
||||
var HEAD_THRUST_STRAFE_SCALE = 2000.0;
|
||||
var HEAD_YAW_RATE = 1.0;
|
||||
var HEAD_PITCH_RATE = 1.0;
|
||||
var HEAD_ROLL_THRUST_SCALE = 75.0;
|
||||
var HEAD_PITCH_LIFT_THRUST = 3.0;
|
||||
var WALL_BOUNCE = 4000.0;
|
||||
|
||||
// If these values are set to something
|
||||
var maxVelocity = 1.25;
|
||||
var noFly = true;
|
||||
|
||||
//var roomLimits = { xMin: 618, xMax: 635.5, zMin: 528, zMax: 552.5 };
|
||||
var roomLimits = { xMin: -1, xMax: 0, zMin: 0, zMax: 0 };
|
||||
|
||||
function isInRoom(position) {
|
||||
var BUFFER = 2.0;
|
||||
if (roomLimits.xMin < 0) {
|
||||
return false;
|
||||
}
|
||||
if ((position.x > (roomLimits.xMin - BUFFER)) &&
|
||||
(position.x < (roomLimits.xMax + BUFFER)) &&
|
||||
(position.z > (roomLimits.zMin - BUFFER)) &&
|
||||
(position.z < (roomLimits.zMax + BUFFER)))
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function moveWithHead(deltaTime) {
|
||||
var thrust = { x: 0, y: 0, z: 0 };
|
||||
var position = MyAvatar.position;
|
||||
if (movingWithHead) {
|
||||
var deltaYaw = MyAvatar.getHeadFinalYaw() - headStartYaw;
|
||||
var deltaPitch = MyAvatar.getHeadDeltaPitch() - headStartDeltaPitch;
|
||||
|
||||
var deltaRoll = MyAvatar.getHeadFinalRoll() - headStartRoll;
|
||||
var velocity = MyAvatar.getVelocity();
|
||||
var bodyLocalCurrentHeadVector = Vec3.subtract(MyAvatar.getHeadPosition(), MyAvatar.position);
|
||||
bodyLocalCurrentHeadVector = Vec3.multiplyQbyV(Quat.angleAxis(-deltaYaw, {x:0, y: 1, z:0}), bodyLocalCurrentHeadVector);
|
||||
var headDelta = Vec3.subtract(bodyLocalCurrentHeadVector, headStartPosition);
|
||||
headDelta = Vec3.multiplyQbyV(Quat.inverse(Camera.getOrientation()), headDelta);
|
||||
headDelta.y = 0.0; // Don't respond to any of the vertical component of head motion
|
||||
|
||||
var forward = Quat.getFront(Camera.getOrientation());
|
||||
var right = Quat.getRight(Camera.getOrientation());
|
||||
var up = Quat.getUp(Camera.getOrientation());
|
||||
if (noFly) {
|
||||
forward.y = 0.0;
|
||||
forward = Vec3.normalize(forward);
|
||||
right.y = 0.0;
|
||||
right = Vec3.normalize(right);
|
||||
up = { x: 0, y: 1, z: 0};
|
||||
}
|
||||
|
||||
// Thrust based on leaning forward and side-to-side
|
||||
if (Math.abs(headDelta.z) > HEAD_MOVE_DEAD_ZONE) {
|
||||
MyAvatar.addThrust(Vec3.multiply(Quat.getFront(Camera.getOrientation()), -headDelta.z * HEAD_THRUST_FWD_SCALE * deltaTime));
|
||||
if (Math.abs(Vec3.dot(velocity, forward)) < maxVelocity) {
|
||||
thrust = Vec3.sum(thrust, Vec3.multiply(forward, -headDelta.z * HEAD_THRUST_FWD_SCALE * deltaTime));
|
||||
}
|
||||
}
|
||||
if (Math.abs(headDelta.x) > HEAD_STRAFE_DEAD_ZONE) {
|
||||
MyAvatar.addThrust(Vec3.multiply(Quat.getRight(Camera.getOrientation()), headDelta.x * HEAD_THRUST_STRAFE_SCALE * deltaTime));
|
||||
if (Math.abs(Vec3.dot(velocity, right)) < maxVelocity) {
|
||||
thrust = Vec3.sum(thrust, Vec3.multiply(right, headDelta.x * HEAD_THRUST_STRAFE_SCALE * deltaTime));
|
||||
}
|
||||
}
|
||||
if (Math.abs(deltaYaw) > HEAD_ROTATE_DEAD_ZONE) {
|
||||
var orientation = Quat.multiply(Quat.angleAxis(deltaYaw * HEAD_YAW_RATE * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation);
|
||||
var orientation = Quat.multiply(Quat.angleAxis((deltaYaw + deltaRoll) * HEAD_YAW_RATE * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation);
|
||||
MyAvatar.orientation = orientation;
|
||||
}
|
||||
// Thrust Up/Down based on head pitch
|
||||
MyAvatar.addThrust(Vec3.multiply({ x:0, y:1, z:0 }, (MyAvatar.getHeadFinalPitch() - headStartFinalPitch) * HEAD_PITCH_LIFT_THRUST * deltaTime));
|
||||
if (!noFly) {
|
||||
if ((Math.abs(Vec3.dot(velocity, up)) < maxVelocity)) {
|
||||
thrust = Vec3.sum(thrust, Vec3.multiply({ x:0, y:1, z:0 }, (MyAvatar.getHeadFinalPitch() - headStartFinalPitch) * HEAD_PITCH_LIFT_THRUST * deltaTime));
|
||||
}
|
||||
}
|
||||
// For head trackers, adjust pitch by head pitch
|
||||
MyAvatar.headPitch += deltaPitch * HEAD_PITCH_RATE * deltaTime;
|
||||
// Thrust strafe based on roll ange
|
||||
MyAvatar.addThrust(Vec3.multiply(Quat.getRight(Camera.getOrientation()), -(MyAvatar.getHeadFinalRoll() - headStartRoll) * HEAD_ROLL_THRUST_SCALE * deltaTime));
|
||||
|
||||
}
|
||||
if (isInRoom(position)) {
|
||||
// Impose constraints to keep you in the space
|
||||
if (position.x < roomLimits.xMin) {
|
||||
thrust.x += (roomLimits.xMin - position.x) * WALL_BOUNCE * deltaTime;
|
||||
} else if (position.x > roomLimits.xMax) {
|
||||
thrust.x += (roomLimits.xMax - position.x) * WALL_BOUNCE * deltaTime;
|
||||
}
|
||||
if (position.z < roomLimits.zMin) {
|
||||
thrust.z += (roomLimits.zMin - position.z) * WALL_BOUNCE * deltaTime;
|
||||
} else if (position.z > roomLimits.zMax) {
|
||||
thrust.z += (roomLimits.zMax - position.z) * WALL_BOUNCE * deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Check against movement box limits
|
||||
|
||||
MyAvatar.addThrust(thrust);
|
||||
}
|
||||
|
||||
Controller.keyPressEvent.connect(function(event) {
|
||||
|
|
|
@ -37,7 +37,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) {
|
|||
glm::quat rotation = getRotation();
|
||||
|
||||
|
||||
const bool useGlutCube = false;
|
||||
const bool useGlutCube = true;
|
||||
|
||||
if (useGlutCube) {
|
||||
glColor3ub(getColor()[RED_INDEX], getColor()[GREEN_INDEX], getColor()[BLUE_INDEX]);
|
||||
|
|
Loading…
Reference in a new issue