Skip to content

Commit

Permalink
Vectors multiplication fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Jun 4, 2023
1 parent 5666181 commit 66570b5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
13 changes: 2 additions & 11 deletions CVRLua/Lua/LuaDefs/QuaternionDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 12 additions & 4 deletions CVRLua/Lua/LuaDefs/Vector2Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 12 additions & 4 deletions CVRLua/Lua/LuaDefs/Vector3Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 12 additions & 4 deletions CVRLua/Lua/LuaDefs/Vector4Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 66570b5

Please sign in to comment.