mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 00:10:52 +02:00
change Voxels JS interface to be more clear
This commit is contained in:
parent
7ce774da70
commit
abf8e83c33
5 changed files with 37 additions and 39 deletions
|
@ -24,7 +24,7 @@ function checkController() {
|
|||
var numberOfTriggers = Controller.getNumberOfTriggers();
|
||||
var numberOfSpatialControls = Controller.getNumberOfSpatialControls();
|
||||
var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers;
|
||||
|
||||
|
||||
// this is expected for hydras
|
||||
if (numberOfTriggers == 2 && controllersPerTrigger == 2) {
|
||||
for (var t = 0; t < numberOfTriggers; t++) {
|
||||
|
@ -43,38 +43,38 @@ function checkController() {
|
|||
shootABullet = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (shootABullet) {
|
||||
var palmController = t * controllersPerTrigger;
|
||||
var palmController = t * controllersPerTrigger;
|
||||
var palmPosition = Controller.getSpatialControlPosition(palmController);
|
||||
|
||||
var fingerTipController = palmController + 1;
|
||||
var fingerTipController = palmController + 1;
|
||||
var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController);
|
||||
|
||||
|
||||
var bulletSize = 0.25/TREE_SCALE;
|
||||
|
||||
var palmInParticleSpace =
|
||||
{ x: palmPosition.x/TREE_SCALE,
|
||||
y: palmPosition.y/TREE_SCALE,
|
||||
var palmInParticleSpace =
|
||||
{ x: palmPosition.x/TREE_SCALE,
|
||||
y: palmPosition.y/TREE_SCALE,
|
||||
z: palmPosition.z/TREE_SCALE };
|
||||
|
||||
var tipInParticleSpace =
|
||||
{ x: fingerTipPosition.x/TREE_SCALE,
|
||||
y: fingerTipPosition.y/TREE_SCALE,
|
||||
|
||||
var tipInParticleSpace =
|
||||
{ x: fingerTipPosition.x/TREE_SCALE,
|
||||
y: fingerTipPosition.y/TREE_SCALE,
|
||||
z: fingerTipPosition.z/TREE_SCALE };
|
||||
|
||||
var palmToFingerTipVector =
|
||||
var palmToFingerTipVector =
|
||||
{ x: (tipInParticleSpace.x - palmInParticleSpace.x),
|
||||
y: (tipInParticleSpace.y - palmInParticleSpace.y),
|
||||
z: (tipInParticleSpace.z - palmInParticleSpace.z) };
|
||||
|
||||
|
||||
// just off the front of the finger tip
|
||||
var position = { x: tipInParticleSpace.x + palmToFingerTipVector.x/2,
|
||||
y: tipInParticleSpace.y + palmToFingerTipVector.y/2,
|
||||
z: tipInParticleSpace.z + palmToFingerTipVector.z/2};
|
||||
var position = { x: tipInParticleSpace.x + palmToFingerTipVector.x/2,
|
||||
y: tipInParticleSpace.y + palmToFingerTipVector.y/2,
|
||||
z: tipInParticleSpace.z + palmToFingerTipVector.z/2};
|
||||
|
||||
var linearVelocity = 50; // 50 meters per second
|
||||
|
||||
|
||||
var velocity = { x: palmToFingerTipVector.x * linearVelocity,
|
||||
y: palmToFingerTipVector.y * linearVelocity,
|
||||
z: palmToFingerTipVector.z * linearVelocity };
|
||||
|
@ -85,7 +85,7 @@ function checkController() {
|
|||
var inHand = false;
|
||||
|
||||
// This is the script for the particles that this gun shoots.
|
||||
var script =
|
||||
var script =
|
||||
" function collisionWithVoxel(voxel) { " +
|
||||
" print('collisionWithVoxel(voxel)... '); " +
|
||||
" print('myID=' + Particle.getID() + '\\n'); " +
|
||||
|
@ -96,17 +96,17 @@ function checkController() {
|
|||
" Particle.setColor(voxelColor); " +
|
||||
" var voxelAt = voxel.getPosition();" +
|
||||
" var voxelScale = voxel.getScale();" +
|
||||
" Voxels.queueVoxelDelete(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " +
|
||||
" print('Voxels.queueVoxelDelete(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " +
|
||||
" Voxels.eraseVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " +
|
||||
" print('Voxels.eraseVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " +
|
||||
" } " +
|
||||
" Particle.collisionWithVoxel.connect(collisionWithVoxel); ";
|
||||
|
||||
|
||||
Particles.queueParticleAdd(position, bulletSize, color, velocity, gravity, damping, inHand, script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// register the call back so it fires before each data send
|
||||
Agent.willSendVisualDataCallback.connect(checkController);
|
||||
|
|
|
@ -1561,8 +1561,8 @@ void Application::shootParticle() {
|
|||
" Particle.setColor(voxelColor); "
|
||||
" var voxelAt = voxel.getPosition();"
|
||||
" var voxelScale = voxel.getScale();"
|
||||
" Voxels.queueVoxelDelete(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); "
|
||||
" print('Voxels.queueVoxelDelete(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); "
|
||||
" Voxels.eraseVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); "
|
||||
" print('Voxels.eraseVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); "
|
||||
" } "
|
||||
" Particle.collisionWithVoxel.connect(collisionWithVoxel); " );
|
||||
|
||||
|
|
|
@ -145,7 +145,6 @@ void ScriptEngine::evaluate() {
|
|||
}
|
||||
|
||||
QScriptValue result = _engine.evaluate(_scriptContents);
|
||||
qDebug() << "Evaluated script.\n";
|
||||
|
||||
if (_engine.hasUncaughtException()) {
|
||||
int line = _engine.uncaughtExceptionLineNumber();
|
||||
|
@ -160,7 +159,6 @@ void ScriptEngine::run() {
|
|||
_isRunning = true;
|
||||
|
||||
QScriptValue result = _engine.evaluate(_scriptContents);
|
||||
qDebug() << "Evaluated script.\n";
|
||||
|
||||
if (_engine.hasUncaughtException()) {
|
||||
int line = _engine.uncaughtExceptionLineNumber();
|
||||
|
|
|
@ -12,28 +12,28 @@ void VoxelsScriptingInterface::queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDet
|
|||
getVoxelPacketSender()->queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails);
|
||||
}
|
||||
|
||||
void VoxelsScriptingInterface::queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) {
|
||||
void VoxelsScriptingInterface::setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) {
|
||||
// setup a VoxelDetail struct with the data
|
||||
VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue};
|
||||
|
||||
|
||||
// queue the packet
|
||||
queueVoxelAdd(PACKET_TYPE_VOXEL_SET, addVoxelDetail);
|
||||
}
|
||||
|
||||
void VoxelsScriptingInterface::queueDestructiveVoxelAdd(float x, float y, float z, float scale,
|
||||
void VoxelsScriptingInterface::destructiveSetVoxel(float x, float y, float z, float scale,
|
||||
uchar red, uchar green, uchar blue) {
|
||||
// setup a VoxelDetail struct with the data
|
||||
VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue};
|
||||
|
||||
|
||||
// queue the destructive add
|
||||
queueVoxelAdd(PACKET_TYPE_VOXEL_SET_DESTRUCTIVE, addVoxelDetail);
|
||||
}
|
||||
|
||||
void VoxelsScriptingInterface::queueVoxelDelete(float x, float y, float z, float scale) {
|
||||
|
||||
void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale) {
|
||||
|
||||
// setup a VoxelDetail struct with data
|
||||
VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0};
|
||||
|
||||
|
||||
getVoxelPacketSender()->queueVoxelEditMessages(PACKET_TYPE_VOXEL_ERASE, 1, &deleteVoxelDetail);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ public slots:
|
|||
/// \param red the R value for RGB color of voxel
|
||||
/// \param green the G value for RGB color of voxel
|
||||
/// \param blue the B value for RGB color of voxel
|
||||
void queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue);
|
||||
|
||||
void setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue);
|
||||
|
||||
/// queues the destructive creation of a voxel which will be sent by calling process on the PacketSender
|
||||
/// \param x the x-coordinate of the voxel (in VS space)
|
||||
/// \param y the y-coordinate of the voxel (in VS space)
|
||||
|
@ -43,14 +43,14 @@ public slots:
|
|||
/// \param red the R value for RGB color of voxel
|
||||
/// \param green the G value for RGB color of voxel
|
||||
/// \param blue the B value for RGB color of voxel
|
||||
void queueDestructiveVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue);
|
||||
|
||||
void destructiveSetVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue);
|
||||
|
||||
/// queues the deletion of a voxel, sent by calling process on the PacketSender
|
||||
/// \param x the x-coordinate of the voxel (in VS space)
|
||||
/// \param y the y-coordinate of the voxel (in VS space)
|
||||
/// \param z the z-coordinate of the voxel (in VS space)
|
||||
/// \param scale the scale of the voxel (in VS space)
|
||||
void queueVoxelDelete(float x, float y, float z, float scale);
|
||||
void eraseVoxel(float x, float y, float z, float scale);
|
||||
|
||||
private:
|
||||
void queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails);
|
||||
|
|
Loading…
Reference in a new issue