Use Graphics.transformVertices and convert rotation to radians
parent
8f7bd34693
commit
dfd127f498
|
|
@ -252,8 +252,7 @@ function drawElement(pos, offset, path, lastElem){
|
||||||
//print("drawImage from drawElement", image, pos, offset);
|
//print("drawImage from drawElement", image, pos, offset);
|
||||||
var options={};
|
var options={};
|
||||||
if (pos.RotationValue){
|
if (pos.RotationValue){
|
||||||
options.rotate = scaledown(pos.RotationValue, pos.MinRotationValue, pos.MaxRotationValue);
|
options.rotate = radians(pos);
|
||||||
options.rotate = options.rotate * Math.PI* 2;
|
|
||||||
}
|
}
|
||||||
if (pos.Scale){
|
if (pos.Scale){
|
||||||
options.scale = pos.ScaleValue;
|
options.scale = pos.ScaleValue;
|
||||||
|
|
@ -439,23 +438,12 @@ function scaledown(value, min, max){
|
||||||
return scaled;
|
return scaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function rotate(center, coords, rotation) {
|
function radians(rotation){
|
||||||
startPerfLog("rotate");
|
var value = scaledown(rotation.RotationValue, rotation.MinRotationValue, rotation.MaxRotationValue);
|
||||||
var value = scaledown(rotation.RotationValue, rotation.MinRotationValue, rotation.MaxRotationValue);
|
value -= rotation.RotationOffset ? rotation.RotationOffset : 0;
|
||||||
value -= rotation.RotationOffset ? rotation.RotationOffset : 0;
|
value *= 360;
|
||||||
value *= 360;
|
value *= Math.PI / 180;
|
||||||
value -= 180;
|
return value;
|
||||||
|
|
||||||
//print("Angle", value);
|
|
||||||
|
|
||||||
var radians = (Math.PI / 180) * value,
|
|
||||||
cos = -Math.cos(radians),
|
|
||||||
sin = Math.sin(radians),
|
|
||||||
x = (cos * (coords.X - center.X)) + (sin * (coords.Y - center.Y)) + center.X,
|
|
||||||
y = (cos * (coords.Y - center.Y)) - (sin * (coords.X - center.X)) + center.Y;
|
|
||||||
|
|
||||||
endPerfLog("rotate");
|
|
||||||
return {X:x,Y:y};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawPoly(element, offset){
|
function drawPoly(element, offset){
|
||||||
|
|
@ -467,15 +455,17 @@ function drawPoly(element, offset){
|
||||||
|
|
||||||
startPerfLog("drawPoly_transform");
|
startPerfLog("drawPoly_transform");
|
||||||
for (var c of element.Vertices){
|
for (var c of element.Vertices){
|
||||||
if (element.RotationValue){
|
vertices.push(c.X);
|
||||||
var rotated = rotate({X:0,Y:0}, c, element);
|
vertices.push(c.Y);
|
||||||
vertices.push(rotated.X + primitiveOffset.X);
|
|
||||||
vertices.push(rotated.Y + primitiveOffset.Y);
|
|
||||||
} else {
|
|
||||||
vertices.push(c.X + primitiveOffset.X);
|
|
||||||
vertices.push(c.Y + primitiveOffset.Y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
var transform = { x: primitiveOffset.X,
|
||||||
|
y: primitiveOffset.Y
|
||||||
|
};
|
||||||
|
if (element.RotationValue){
|
||||||
|
transform.rotate = radians(element);
|
||||||
|
}
|
||||||
|
vertices = g.transformVertices(vertices, transform);
|
||||||
|
|
||||||
endPerfLog("drawPoly_transform");
|
endPerfLog("drawPoly_transform");
|
||||||
|
|
||||||
if (element.ForegroundColor) g.setColor(element.ForegroundColor);
|
if (element.ForegroundColor) g.setColor(element.ForegroundColor);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue