mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 07:13:10 +02:00
Clean up line.js and make lifetime settable
This commit is contained in:
parent
2abb6a2fd5
commit
983c551ce3
2 changed files with 20 additions and 14 deletions
|
@ -1,12 +1,15 @@
|
||||||
Script.include("../libraries/line.js");
|
Script.include("../libraries/line.js");
|
||||||
|
|
||||||
var basePosition = MyAvatar.position;
|
var basePosition = MyAvatar.position;
|
||||||
var line = new InfiniteLine(basePosition);
|
var color = { red: 128, green: 220, blue: 190 };
|
||||||
|
var strokeWidth = 0.01;
|
||||||
|
var line = new InfiniteLine(basePosition, color, 20);
|
||||||
|
|
||||||
for (var i = 0; i < (16 * Math.PI); i += 0.05) {
|
for (var i = 0; i < (16 * Math.PI); i += 0.05) {
|
||||||
var x = 0
|
var x = 0
|
||||||
var y = 0.25 * Math.sin(i);
|
var y = 0.25 * Math.sin(i);
|
||||||
var z = i / 10;
|
var z = i / 10;
|
||||||
|
|
||||||
line.enqueuePoint(Vec3.sum(basePosition, { x: x, y: y, z: z }));
|
var position = Vec3.sum(basePosition, { x: x, y: y, z: z });
|
||||||
|
line.enqueuePoint(position, strokeWidth);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,13 @@ function error(message) {
|
||||||
// PolyLine
|
// PolyLine
|
||||||
var LINE_DIMENSIONS = { x: 2000, y: 2000, z: 2000 };
|
var LINE_DIMENSIONS = { x: 2000, y: 2000, z: 2000 };
|
||||||
var MAX_LINE_LENGTH = 40; // This must be 2 or greater;
|
var MAX_LINE_LENGTH = 40; // This must be 2 or greater;
|
||||||
var PolyLine = function(position, color, defaultStrokeWidth) {
|
var DEFAULT_STROKE_WIDTH = 0.1;
|
||||||
|
var DEFAULT_LIFETIME = 20;
|
||||||
|
var DEFAULT_COLOR = { red: 255, green: 255, blue: 255 };
|
||||||
|
var PolyLine = function(position, color, lifetime) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.defaultStrokeWidth = defaultStrokeWidth;
|
this.lifetime = lifetime === undefined ? DEFAULT_LIFETIME : lifetime;
|
||||||
this.points = [
|
this.points = [
|
||||||
];
|
];
|
||||||
this.strokeWidths = [
|
this.strokeWidths = [
|
||||||
|
@ -23,11 +26,11 @@ var PolyLine = function(position, color, defaultStrokeWidth) {
|
||||||
strokeWidths: this.strokeWidths,
|
strokeWidths: this.strokeWidths,
|
||||||
dimensions: LINE_DIMENSIONS,
|
dimensions: LINE_DIMENSIONS,
|
||||||
color: color,
|
color: color,
|
||||||
lifetime: 20
|
lifetime: lifetime
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
PolyLine.prototype.enqueuePoint = function(position) {
|
PolyLine.prototype.enqueuePoint = function(position, strokeWidth) {
|
||||||
if (this.isFull()) {
|
if (this.isFull()) {
|
||||||
error("Hit max PolyLine size");
|
error("Hit max PolyLine size");
|
||||||
return;
|
return;
|
||||||
|
@ -36,7 +39,7 @@ PolyLine.prototype.enqueuePoint = function(position) {
|
||||||
position = Vec3.subtract(position, this.position);
|
position = Vec3.subtract(position, this.position);
|
||||||
this.points.push(position);
|
this.points.push(position);
|
||||||
this.normals.push({ x: 1, y: 0, z: 0 });
|
this.normals.push({ x: 1, y: 0, z: 0 });
|
||||||
this.strokeWidths.push(this.defaultStrokeWidth);
|
this.strokeWidths.push(strokeWidth);
|
||||||
Entities.editEntity(this.entityID, {
|
Entities.editEntity(this.entityID, {
|
||||||
linePoints: this.points,
|
linePoints: this.points,
|
||||||
normals: this.normals,
|
normals: this.normals,
|
||||||
|
@ -83,33 +86,33 @@ PolyLine.prototype.destroy = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// InfiniteLine
|
// InfiniteLine
|
||||||
InfiniteLine = function(position, color) {
|
InfiniteLine = function(position, color, lifetime) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.lifetime = lifetime === undefined ? DEFAULT_LIFETIME : lifetime;
|
||||||
this.lines = [new PolyLine(position, color, 0.01)];
|
this.lines = [new PolyLine(position, color, 0.01)];
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
InfiniteLine.prototype.enqueuePoint = function(position) {
|
InfiniteLine.prototype.enqueuePoint = function(position, strokeWidth) {
|
||||||
var currentLine;
|
var currentLine;
|
||||||
|
|
||||||
if (this.lines.length == 0) {
|
if (this.lines.length == 0) {
|
||||||
currentLine = new PolyLine(position, this.color, 0.01);
|
currentLine = new PolyLine(position, this.color, this.lifetime);
|
||||||
this.lines.push(currentLine);
|
this.lines.push(currentLine);
|
||||||
} else {
|
} else {
|
||||||
currentLine = this.lines[this.lines.length - 1];
|
currentLine = this.lines[this.lines.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentLine.isFull()) {
|
if (currentLine.isFull()) {
|
||||||
var newLine = new PolyLine(currentLine.getLastPoint(), this.color, 0.01);
|
var newLine = new PolyLine(currentLine.getLastPoint(), this.color, this.lifetime);
|
||||||
newLine.enqueuePoint(currentLine.getLastPoint());
|
newLine.enqueuePoint(currentLine.getLastPoint(), strokeWidth);
|
||||||
this.lines.push(newLine);
|
this.lines.push(newLine);
|
||||||
currentLine = newLine;
|
currentLine = newLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLine.enqueuePoint(position);
|
currentLine.enqueuePoint(position, strokeWidth);
|
||||||
|
|
||||||
++this.size;
|
++this.size;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue