public static int Length(ILuaState lua) { if (!lua.IsTable(-1)) { lua.PushNumber(0); return(1); } Vector3 srcPos = LuaDataReadHelper.GetLuaVector3(lua); Vector3 dstPos = LuaDataReadHelper.GetLuaVector3(lua); double len = (srcPos - dstPos).magnitude; lua.PushNumber(len); return(1); }
public static int Angle(ILuaState lua) { if (!lua.IsTable(-1)) { lua.PushNumber(0); return(1); } Vector3 srcPos = LuaDataReadHelper.GetLuaVector3(lua); Vector3 dstPos = LuaDataReadHelper.GetLuaVector3(lua); Vector3 oriPos = LuaDataReadHelper.GetLuaVector3(lua); Vector3 oriDir = dstPos - oriPos; Vector3 nowDir = dstPos - srcPos; oriDir.Normalize(); nowDir.Normalize(); double angle = Vector3.Angle(oriDir, nowDir); lua.PushNumber(angle); return(1); }
public static int Translate(ILuaState lua) { if (!lua.IsTable(-1)) { lua.PushNumber(0); lua.PushNumber(0); lua.PushNumber(0); return(3); } Vector3 srcPos = LuaDataReadHelper.GetLuaVector3(lua); Vector3 dir = LuaDataReadHelper.GetLuaVector3(lua); dir.Normalize(); float delta = (float)lua.L_CheckNumber(7); srcPos = srcPos + dir * delta; lua.PushNumber(srcPos.x); lua.PushNumber(srcPos.y); lua.PushNumber(srcPos.z); return(3); }