mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 00:40:06 +02:00
Merge pull request #2966 from Atlante45/grab_attachements
First pass at grabbing attachment
This commit is contained in:
commit
a257af76dc
1 changed files with 58 additions and 4 deletions
|
@ -306,6 +306,18 @@ function controller(wichSide) {
|
||||||
|
|
||||||
this.oldModelRotation = newRotation;
|
this.oldModelRotation = newRotation;
|
||||||
this.oldModelPosition = newPosition;
|
this.oldModelPosition = newPosition;
|
||||||
|
|
||||||
|
var indicesToRemove = [];
|
||||||
|
for (var i = 0; i < this.jointsIntersectingFromStart.length; ++i) {
|
||||||
|
var distance = Vec3.distance(MyAvatar.getJointPosition(this.jointsIntersectingFromStart[i]), this.oldModelPosition);
|
||||||
|
if (distance >= this.oldModelRadius) {
|
||||||
|
indicesToRemove.push(this.jointsIntersectingFromStart[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
for (var i = 0; i < indicesToRemove.length; ++i) {
|
||||||
|
this.jointsIntersectingFromStart.splice(this.jointsIntersectingFromStart.indexOf(indicesToRemove[i], 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,6 +351,43 @@ function controller(wichSide) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.pressing) {
|
if (this.pressing) {
|
||||||
|
// Checking for attachments intersecting
|
||||||
|
var attachments = MyAvatar.getAttachmentData();
|
||||||
|
var attachmentIndex = -1;
|
||||||
|
var attachmentX = LASER_LENGTH_FACTOR;
|
||||||
|
|
||||||
|
for (var i = 0; i < attachments.length; ++i) {
|
||||||
|
var position = Vec3.sum(MyAvatar.getJointPosition(attachments[i].jointName), attachments[i].translation);
|
||||||
|
var scale = attachments[i].scale;
|
||||||
|
|
||||||
|
var A = this.palmPosition;
|
||||||
|
var B = this.front;
|
||||||
|
var P = position;
|
||||||
|
|
||||||
|
var x = Vec3.dot(Vec3.subtract(P, A), B);
|
||||||
|
var X = Vec3.sum(A, Vec3.multiply(B, x));
|
||||||
|
var d = Vec3.length(Vec3.subtract(P, X));
|
||||||
|
|
||||||
|
if (d < scale / 2.0 && 0 < x && x < attachmentX) {
|
||||||
|
attachmentIndex = i;
|
||||||
|
attachmentX = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attachmentIndex != -1) {
|
||||||
|
MyAvatar.detachOne(attachments[attachmentIndex].modelURL, attachments[attachmentIndex].jointName);
|
||||||
|
Models.addModel({
|
||||||
|
position: Vec3.sum(MyAvatar.getJointPosition(attachments[attachmentIndex].jointName),
|
||||||
|
attachments[attachmentIndex].translation),
|
||||||
|
modelRotation: Quat.multiply(MyAvatar.getJointCombinedRotation(attachments[attachmentIndex].jointName),
|
||||||
|
attachments[attachmentIndex].rotation),
|
||||||
|
radius: attachments[attachmentIndex].scale / 2.0,
|
||||||
|
modelURL: attachments[attachmentIndex].modelURL
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is none so ...
|
||||||
|
// Checking model tree
|
||||||
Vec3.print("Looking at: ", this.palmPosition);
|
Vec3.print("Looking at: ", this.palmPosition);
|
||||||
var pickRay = { origin: this.palmPosition,
|
var pickRay = { origin: this.palmPosition,
|
||||||
direction: Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)) };
|
direction: Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)) };
|
||||||
|
@ -519,10 +568,15 @@ function mousePressEvent(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
||||||
Models.addModel({ position: position,
|
|
||||||
radius: radiusDefault,
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
modelURL: url
|
Models.addModel({ position: position,
|
||||||
});
|
radius: radiusDefault,
|
||||||
|
modelURL: url
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
print("Can't create model: Model would be out of bounds.");
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
|
|
Loading…
Reference in a new issue