From 66570b51d56cbbeb373627a71a4c81acce106eb3 Mon Sep 17 00:00:00 2001 From: SDraw Date: Sun, 4 Jun 2023 03:02:08 +0300 Subject: [PATCH] Vectors multiplication fix --- CVRLua/Lua/LuaDefs/QuaternionDefs.cs | 13 ++----------- CVRLua/Lua/LuaDefs/Vector2Defs.cs | 16 ++++++++++++---- CVRLua/Lua/LuaDefs/Vector3Defs.cs | 16 ++++++++++++---- CVRLua/Lua/LuaDefs/Vector4Defs.cs | 16 ++++++++++++---- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CVRLua/Lua/LuaDefs/QuaternionDefs.cs b/CVRLua/Lua/LuaDefs/QuaternionDefs.cs index 022e0e0..2aeba71 100644 --- a/CVRLua/Lua/LuaDefs/QuaternionDefs.cs +++ b/CVRLua/Lua/LuaDefs/QuaternionDefs.cs @@ -314,19 +314,10 @@ static int Multiply(IntPtr p_state) LuaArgReader l_argReader = new LuaArgReader(p_state); Wrappers.Quaternion l_quatA = null; Wrappers.Quaternion l_quatB = null; - Wrappers.Vector3 l_vecA = null; l_argReader.ReadObject(ref l_quatA); - l_argReader.ReadNextObject(ref l_quatB); - l_argReader.ReadNextObject(ref l_vecA); + l_argReader.ReadObject(ref l_quatB); if(!l_argReader.HasErrors()) - { - if(l_quatB != null) - l_argReader.PushObject(new Wrappers.Quaternion(l_quatA.m_quat * l_quatB.m_quat)); - else if(l_vecA != null) - l_argReader.PushObject(new Wrappers.Vector3(l_quatA.m_quat * l_vecA.m_vec)); - else - l_argReader.PushBoolean(false); - } + l_argReader.PushObject(new Wrappers.Quaternion(l_quatA.m_quat * l_quatB.m_quat)); else l_argReader.PushBoolean(false); diff --git a/CVRLua/Lua/LuaDefs/Vector2Defs.cs b/CVRLua/Lua/LuaDefs/Vector2Defs.cs index d4717c6..17f45be 100644 --- a/CVRLua/Lua/LuaDefs/Vector2Defs.cs +++ b/CVRLua/Lua/LuaDefs/Vector2Defs.cs @@ -109,12 +109,20 @@ static int Subtract(IntPtr p_state) static int Multiply(IntPtr p_state) { LuaArgReader l_argReader = new LuaArgReader(p_state); - Wrappers.Vector2 l_vecA = null; + Wrappers.Vector2 l_vec = null; float l_val = 0f; - l_argReader.ReadObject(ref l_vecA); - l_argReader.ReadNumber(ref l_val); + if(l_argReader.IsNextNumber()) + { + l_argReader.ReadNumber(ref l_val); + l_argReader.ReadObject(ref l_vec); + } + else + { + l_argReader.ReadObject(ref l_vec); + l_argReader.ReadNumber(ref l_val); + } if(!l_argReader.HasErrors()) - l_argReader.PushObject(new Wrappers.Vector2(l_vecA.m_vec * l_val)); + l_argReader.PushObject(new Wrappers.Vector2(l_vec.m_vec * l_val)); else l_argReader.PushBoolean(false); diff --git a/CVRLua/Lua/LuaDefs/Vector3Defs.cs b/CVRLua/Lua/LuaDefs/Vector3Defs.cs index 19fa011..da88ddb 100644 --- a/CVRLua/Lua/LuaDefs/Vector3Defs.cs +++ b/CVRLua/Lua/LuaDefs/Vector3Defs.cs @@ -493,12 +493,20 @@ static int Subtract(IntPtr p_state) static int Multiply(IntPtr p_state) { LuaArgReader l_argReader = new LuaArgReader(p_state); - Wrappers.Vector3 l_vecA = null; + Wrappers.Vector3 l_vec = null; float l_val = 0f; - l_argReader.ReadObject(ref l_vecA); - l_argReader.ReadNumber(ref l_val); + if(l_argReader.IsNextNumber()) + { + l_argReader.ReadNumber(ref l_val); + l_argReader.ReadObject(ref l_vec); + } + else + { + l_argReader.ReadObject(ref l_vec); + l_argReader.ReadNumber(ref l_val); + } if(!l_argReader.HasErrors()) - l_argReader.PushObject(new Wrappers.Vector3(l_vecA.m_vec * l_val)); + l_argReader.PushObject(new Wrappers.Vector3(l_val * l_vec.m_vec)); else l_argReader.PushBoolean(false); diff --git a/CVRLua/Lua/LuaDefs/Vector4Defs.cs b/CVRLua/Lua/LuaDefs/Vector4Defs.cs index b3946bb..75fb602 100644 --- a/CVRLua/Lua/LuaDefs/Vector4Defs.cs +++ b/CVRLua/Lua/LuaDefs/Vector4Defs.cs @@ -281,12 +281,20 @@ static int Subtract(IntPtr p_state) static int Multiply(IntPtr p_state) { LuaArgReader l_argReader = new LuaArgReader(p_state); - Wrappers.Vector4 l_vecA = null; + Wrappers.Vector4 l_vec = null; float l_val = 0f; - l_argReader.ReadObject(ref l_vecA); - l_argReader.ReadNumber(ref l_val); + if(l_argReader.IsNextNumber()) + { + l_argReader.ReadNumber(ref l_val); + l_argReader.ReadObject(ref l_vec); + } + else + { + l_argReader.ReadObject(ref l_vec); + l_argReader.ReadNumber(ref l_val); + } if(!l_argReader.HasErrors()) - l_argReader.PushObject(new Wrappers.Vector4(l_vecA.m_vec * l_val)); + l_argReader.PushObject(new Wrappers.Vector4(l_vec.m_vec * l_val)); else l_argReader.PushBoolean(false);