Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Lerp Vectors node
Browse files Browse the repository at this point in the history
  • Loading branch information
Simonrazer committed Aug 15, 2018
1 parent 547976a commit c1e104e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Sources/armory/logicnode/LerpVectorsNode.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package armory.logicnode;

import iron.math.Vec4;

class LerpVectorsNode extends LogicNode {

var v = new Vec4();
var v1:Vec4;
var v2:Vec4;
var t=0.0;
var c:Float;
var f=0.0;

public function new(tree:LogicTree) {
super(tree);
}

override function run() {
v1 = inputs[1].get();
v2 = inputs[2].get();
t = inputs[3].get();
f = (t / iron.system.Time.delta);
}

override function get(from:Int):Dynamic {
if (v1==null) {
return null;
c=1;
}
if (t>=0) {
trace(t);
v.x=v1.x+((v2.x-v1.x)/f)*c;
v.y=v1.y+((v2.y-v1.y)/f)*c;
v.z=v1.z+((v2.z-v1.z)/f)*c;
t -= iron.system.Time.delta;
c++;
return v;
}
else {c=1; return null;}
}
}
14 changes: 14 additions & 0 deletions blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ def init(self, context):
self.inputs.new('NodeSocketFloat', 'Seconds')
self.inputs.new('NodeSocketInt', 'Repetitions (0 for oneshot, negative for unlimited)')

class LerpVectorsNode(Node, ArmLogicTreeNode):
'''Lerp Vectors node'''
bl_idname = 'LNLerpVectorsNode'
bl_label = 'Lerp Vectors'
bl_icon = 'GAME'

def init(self, context):
self.inputs.new('ArmNodeSocketAction', 'In')
self.inputs.new('NodeSocketVector', 'Starting Vector')
self.inputs.new('NodeSocketVector', 'End Vector')
self.inputs.new('NodeSocketFloat', 'Time For Change')
self.outputs.new('NodeSocketVector', 'Vector')

def register():
# Add custom nodes
# TODO: separate into single .py file per logic node, similar to the main Armory repository
Expand All @@ -235,6 +248,7 @@ def register():
add_node(CameraController, category='Action')
add_node(AnimationControllerNode, category='Animation')
add_node(TimerNode, category='Logic')
add_node(LerpVectorsNode, category='Value')

# Register newly added nodes
arm.nodes_logic.register_nodes()

0 comments on commit c1e104e

Please sign in to comment.