add robot prototype

This commit is contained in:
Redo
2022-10-28 16:28:16 -06:00
parent 5ecd2ce020
commit 8edbb986c7
4 changed files with 27 additions and 34 deletions

View File

@@ -1,12 +1,3 @@
if(!isObject(LuaLogic_RobotBrickGroup)) {
new SimGroup(LuaLogic_RobotBrickGroup)
{
bl_id = 12345678;
name = "\c1Robot";
QuotaObject = GlobalQuota;
};
mainBrickGroup.add(LuaLogic_RobotBrickGroup);
}
datablock StaticShapeData(LuaLogic_RobotShapeData) {
shapeFile = $LuaLogic::Path @ "bricks/special/cube.dts";
@@ -156,8 +147,6 @@ datablock fxDTSBrickData(LogicGate_RobotController_Data) {
};
function LogicGate_RobotController_Data::LuaLogic_Callback(%this, %brick, %data) {
talk("robot cb " @ %brick SPC %data);
%robot = %brick.luaLogicRobot;
if(!isObject(%robot)) { talk("brick " @ %brick @ " has no robot!"); return; }
%pos = %robot.getPosition();
@@ -209,6 +198,12 @@ function LogicGate_RobotController_Data::LuaLogic_Callback(%this, %brick, %data)
LuaLogic_RobotBrickGroup.add(%nbrick);
%nbrick.setTrusted(1);
}
} else if(%first $= "M") { // move
%pos = getWords(%field, 1, 3);
%rot = getWord(%field, 4);
%robot.setTransform(%pos SPC "0 0 1" SPC (%rot*$pi/2));
} else {
talk("invalid robot callback " @ %field);
}
}
@@ -227,7 +222,20 @@ function LogicGate_RobotController_Data::getRelativeVector(%this, %obj, %vec) {
return %x SPC %y SPC %z;
}
function LogicRobot_CreateBrickGroup() {
if(!isObject(LuaLogic_RobotBrickGroup)) {
new SimGroup(LuaLogic_RobotBrickGroup) {
bl_id = 12345678;
name = "\c1Robot";
QuotaObject = GlobalQuota;
};
mainBrickGroup.add(LuaLogic_RobotBrickGroup);
}
}
function LogicGate_RobotController_Data::createRobot(%this, %obj) {
LogicRobot_CreateBrickGroup();
if(isObject(%obj.luaLogicRobot))
%obj.luaLogicRobot.delete();
@@ -246,13 +254,11 @@ function LogicGate_RobotController_Data::createRobot(%this, %obj) {
}
function LogicGate_RobotController_Data::Logic_onRemove(%this, %obj) {
talk("robot remove");
if(isObject(%obj.luaLogicRobot))
%obj.luaLogicRobot.delete();
}
function LogicGate_RobotController_Data::Logic_onPlant(%this, %obj) {
talk("robot plant");
if(!isObject(%obj.luaLogicRobot))
%this.createRobot(%obj);
}