Fixes
This commit is contained in:
@@ -67,23 +67,6 @@ function actor_player:action_update()
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO: remove
|
||||
function vec3_magnitude(_x, _y, _z)
|
||||
return math.sqrt(_x * _x + _y * _y + _z * _z)
|
||||
end
|
||||
|
||||
function vec3_normalize(_x, _y, _z)
|
||||
local mag = vec3_magnitude(_x, _y, _z)
|
||||
if mag == 0 then return 0, 0, 0 end
|
||||
return _x / mag, _y / mag, _z / mag
|
||||
end
|
||||
|
||||
function vec3_cross(_x1, _y1, _z1, _x2, _y2, _z2)
|
||||
return _y1 * _z2 - _y2 * _z1,
|
||||
_z1 * _x2 - _z2 * _x1,
|
||||
_x1 * _y2 - _x2 * _y1
|
||||
end
|
||||
|
||||
function actor_player:update_player_movement(dt)
|
||||
local movement = self:get_movement()
|
||||
local speed = 4.0
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
-- Game initialization script
|
||||
|
||||
-- загружаем скрипты
|
||||
load_script("mathlib.lua")
|
||||
load_script("game_utils.lua")
|
||||
load_script("game_hud.lua")
|
||||
load_script("game_object.lua")
|
||||
|
||||
17
data/scripts/mathlib.lua
Normal file
17
data/scripts/mathlib.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
-- math library
|
||||
|
||||
function vec3_magnitude(_x, _y, _z)
|
||||
return math.sqrt(_x * _x + _y * _y + _z * _z)
|
||||
end
|
||||
|
||||
function vec3_normalize(_x, _y, _z)
|
||||
local mag = vec3_magnitude(_x, _y, _z)
|
||||
if mag == 0 then return 0, 0, 0 end
|
||||
return _x / mag, _y / mag, _z / mag
|
||||
end
|
||||
|
||||
function vec3_cross(_x1, _y1, _z1, _x2, _y2, _z2)
|
||||
return _y1 * _z2 - _y2 * _z1,
|
||||
_z1 * _x2 - _z2 * _x1,
|
||||
_x1 * _y2 - _x2 * _y1
|
||||
end
|
||||
@@ -87,6 +87,7 @@ get_velocity() -- return x, y, z
|
||||
has_rigid_body() -- return boolean
|
||||
create_box_body(float sizex, float sizey, float sizez, float mass, float friction, float damping, bool is_trigger, bool use_parameters)
|
||||
create_sphere_body(float radius, float mass, float friction, float damping, bool is_trigger, bool use_parameters)
|
||||
ForceBodyTransformUpdate() -- hack for forcing entity world transform to the rigid body
|
||||
|
||||
|
||||
find_animation(string name) -- find an animation in the model
|
||||
|
||||
@@ -222,6 +222,7 @@ void Entity::RegisterBaseFunctions()
|
||||
m_luaObject.Register("has_rigid_body", *this, &Entity::Lua_HasRigidBody);
|
||||
m_luaObject.Register("create_box_body", *this, &Entity::Lua_CreateBoxBody);
|
||||
m_luaObject.Register("create_sphere_body", *this, &Entity::Lua_CreateSphereBody);
|
||||
m_luaObject.Register("ForceBodyTransformUpdate", *this, &Entity::Lua_ForceBodyTransformUpdate);
|
||||
|
||||
// animation
|
||||
m_luaObject.Register("find_animation", *this, &Entity::Lua_FindAnimation);
|
||||
@@ -487,6 +488,13 @@ int Entity::Lua_CreateSphereBody(LuaPlus::LuaState* state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Entity::Lua_ForceBodyTransformUpdate(LuaPlus::LuaState* state)
|
||||
{
|
||||
ForceUpdateBodyTranslation();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Entity::Lua_FindAnimation(LuaPlus::LuaState* state)
|
||||
{
|
||||
LuaPlus::LuaStack stack(state);
|
||||
@@ -692,6 +700,18 @@ void Entity::UpdateBodyDirty()
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::ForceUpdateBodyTranslation()
|
||||
{
|
||||
if (!m_rigidBody)
|
||||
return;
|
||||
|
||||
// I'm sure that position is valid
|
||||
btTransform xform;
|
||||
xform.setIdentity();
|
||||
xform.setOrigin(glmVectorToBt(m_position));
|
||||
m_rigidBody->setWorldTransform(xform);
|
||||
}
|
||||
|
||||
REGISTER_ENTITY(WeaponBase);
|
||||
|
||||
WeaponBase::WeaponBase()
|
||||
|
||||
@@ -91,6 +91,7 @@ public:
|
||||
|
||||
void UpdateBody();
|
||||
void UpdateBodyDirty();
|
||||
void ForceUpdateBodyTranslation();
|
||||
|
||||
// Game entity lua bindings
|
||||
|
||||
@@ -125,6 +126,7 @@ public:
|
||||
int Lua_HasRigidBody(LuaPlus::LuaState* state);
|
||||
int Lua_CreateBoxBody(LuaPlus::LuaState* state);
|
||||
int Lua_CreateSphereBody(LuaPlus::LuaState* state);
|
||||
int Lua_ForceBodyTransformUpdate(LuaPlus::LuaState* state);
|
||||
|
||||
int Lua_FindAnimation(LuaPlus::LuaState* state);
|
||||
int Lua_PlayAnimation(LuaPlus::LuaState* state);
|
||||
|
||||
Reference in New Issue
Block a user