Merge pull request #1578 from MoritzBrueckner/fixes

Some smaller fixes
This commit is contained in:
Lubos Lenco 2020-02-19 21:40:53 +01:00 committed by GitHub
commit becda78736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 14 deletions

View file

@ -1,5 +1,7 @@
package armory.logicnode;
import kha.arrays.Float32Array;
class AddGroupNode extends LogicNode {
public function new(tree: LogicTree) {
@ -18,7 +20,7 @@ class AddGroupNode extends LogicNode {
}
}
raw.groups.push({ name: groupName, object_refs: [] });
raw.groups.push({ name: groupName, object_refs: [], instance_offset: new Float32Array(3)});
runOutput(0);
}
}

View file

@ -1,5 +1,7 @@
package armory.math;
import iron.math.Vec4;
class Helper {
/**
@ -31,7 +33,7 @@ class Helper {
return Math.PI / 180 * degrees;
}
/**
* rounds the precision of a float (default 2).
* Rounds the precision of a float (default 2).
* @return float with rounded precision
*/
public static function roundfp(f: Float, precision = 2): Float {
@ -39,16 +41,23 @@ class Helper {
return std.Math.round(f) / std.Math.pow(10, precision);
}
/**
* clamps a float within some limits.
* Clamps a float within some limits.
* @return same float, min or max if exceeded limits.
*/
public static function clamp(f: Float, min: Float, max: Float): Float {
return f < min ? min : f > max ? max : f;
}
/*
* Convenience function to map a variable from one coordinate space
* to another. Equivalent to unlerp() followed by lerp().
*/
/**
* Convenience function to map a variable from one coordinate space to
* another. Equivalent to unlerp() followed by lerp().
* @param value
* @param leftMin The lower bound of the input coordinate space
* @param leftMax The higher bound of the input coordinate space
* @param rightMin The lower bound of the output coordinate space
* @param rightMax The higher bound of the output coordinate space
* @return Float
*/
public static inline function map(value: Float, leftMin: Float, leftMax: Float, rightMin: Float, rightMax: Float): Float {
return rightMin + (value - leftMin) / (leftMax - leftMin) * (rightMax- rightMin);
}

View file

@ -1,6 +1,7 @@
package armory.math;
import kha.FastFloat;
import iron.math.Mat4;
class Rotator {
public var pitch: FastFloat; // X - look up or down around the X axis
@ -14,16 +15,16 @@ class Rotator {
}
public function toDegrees(): Rotator {
pitch = Math.toDegrees(pitch);
roll = Math.toDegrees(roll);
yaw = Math.toDegrees(yaw);
pitch = Helper.radToDeg(pitch);
roll = Helper.radToDeg(roll);
yaw = Helper.radToDeg(yaw);
return this;
}
public function toRadians(): Rotator {
pitch = Math.toRadians(pitch);
roll = Math.toRadians(roll);
yaw = Math.toRadians(yaw);
pitch = Helper.degToRad(pitch);
roll = Helper.degToRad(roll);
yaw = Helper.degToRad(yaw);
return this;
}
@ -182,7 +183,7 @@ class Rotator {
}
public static inline function clampAxis(angle: FastFloat): FastFloat {
angle = Math.mod(angle, 360); // Makes the angle between -360 and +360
angle = angle % 360; // Makes the angle between -360 and +360
if (angle < 0.0) angle += 360.0;
return angle;
}