Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new C++ support #106

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Joe Fenton
Misty De Meo
Romulo Leitão
Romulo Leitao
AJBats
misscelan
Tiago Rezende
Expand Down
6 changes: 6 additions & 0 deletions libyaul/build-files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ LIB_SRCS+= \
gamemath/fix16/fix16_vec2.c \
gamemath/fix16/fix16_vec3.c \
\
gamemath/c++/angle.cxx \
gamemath/fix16/c++/fix16.cxx \
gamemath/fix16/c++/fix16_vec2.cxx \
gamemath/fix16/c++/fix16_vec3.cxx \
gamemath/fix16/c++/fix16_mat33.cxx \
gamemath/fix16/c++/fix16_mat43.cxx \
gamemath/fix16/c++/fix16_quat.cxx \
\
gamemath/int16.c \
gamemath/int32.c \
Expand Down
8 changes: 8 additions & 0 deletions libyaul/gamemath/c++/angle.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <gamemath/gamemath/angle.h>

#if defined(__cplusplus)

namespace yaul {
} // namespace yaul

#endif /* __cplusplus */
65 changes: 65 additions & 0 deletions libyaul/gamemath/fix16/c++/fix16.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*-
* Copyright (c) Authors of libfixmath
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <assert.h>

#include <cpu/divu.h>
#include <gamemath/angle.h>
#include <gamemath/fix16.h>
#include <stdbool.h>

namespace yaul {

angle
fix16::rad_to_angle() const
{
constexpr fix16 OneOver2Pi { FIX16(1.0 / (2.0 * M_PI)) };
return angle { static_cast<::angle_t>((*this * OneOver2Pi).value) };
}

angle
fix16::deg_to_angle() const
{
constexpr fix16 OneOver2Pi { FIX16(1.0 / (2.0 * M_PI)) };
return angle { static_cast<::angle_t>((deg_to_rad() * OneOver2Pi).value) };
}

void
fix16::start_divu_1_over_value(fix16 v)
{
::cpu_divu_fix16_set(One.value, v.value);
}

void
fix16::start_divu(fix16 num, fix16 denom)
{
::cpu_divu_fix16_set(num.value, denom.value);
}

fix16
fix16::get_divu_quotient()
{
return fix16 { static_cast<fix16_t>(::cpu_divu_quotient_get()) };
}

} // namespace yaul
35 changes: 35 additions & 0 deletions libyaul/gamemath/fix16/c++/fix16_mat33.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c)
* See LICENSE for details.
*
* Mattias Jansson
* Israel Jacquez <[email protected]>
* Romulo Leitao <[email protected]>
*/

#include <assert.h>

#include <gamemath/fix16/fix16_mat33.h>
#include <gamemath/math3d.h>

namespace yaul {

fix16_mat33
fix16_mat33::look_at(const fix16_vec3 &from, const fix16_vec3 &to,
const fix16_vec3 &up)
{
fix16_mat33 result;

lookat_t lookat;
lookat.from = from.as_fix16_vec3_t();
lookat.to = to.as_fix16_vec3_t();
lookat.up = up.as_fix16_vec3_t();
lookat.basis_right = result.row[0].as_fix16_vec3_t();
lookat.basis_up = result.row[1].as_fix16_vec3_t();
lookat.basis_forward = result.row[2].as_fix16_vec3_t();

math3d_lookat(&lookat);
return result;
}

} // namespace yaul
8 changes: 8 additions & 0 deletions libyaul/gamemath/fix16/c++/fix16_mat43.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <gamemath/fix16/fix16_mat43.h>

#if defined(__cplusplus)

namespace yaul {
} // namespace yaul

#endif /* __cplusplus */
8 changes: 8 additions & 0 deletions libyaul/gamemath/fix16/c++/fix16_plane.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <gamemath/fix16/fix16_plane.h>

#if defined(__cplusplus)

namespace yaul {
} // namespace yaul

#endif /* __cplusplus */
8 changes: 8 additions & 0 deletions libyaul/gamemath/fix16/c++/fix16_quat.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <gamemath/fix16/fix16_quat.h>

#if defined(__cplusplus)

namespace yaul {
} // namespace yaul

#endif /* __cplusplus */
8 changes: 8 additions & 0 deletions libyaul/gamemath/fix16/c++/fix16_vec2.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <gamemath/fix16/fix16_vec2.h>

#if defined(__cplusplus)

namespace yaul {
} // namespace yaul

#endif /* __cplusplus */
26 changes: 11 additions & 15 deletions libyaul/gamemath/fix16/c++/fix16_vec3.cxx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#include <gamemath/fix16/fix16_vec3.h>
#include <gamemath/fix16/fix16_quat.h>

bool fix16_vec3_t::is_near_zero(fix16_t epsilon) const {
// TODO: Implement this in C and use it here
return x.is_near_zero(epsilon) && y.is_near_zero(epsilon) && z.is_near_zero(epsilon);
}
#if defined(__cplusplus)

namespace yaul {

void fix16_vec3_t::end_normalization() {
const fix16_t scale = fix16_t{cpu_divu_quotient_get()};
const fix16_vec3 fix16_vec3::operator*(const fix16_quat &other) const
{
fix16_vec3_t result;
fix16_quat_vec3_mul(other.as_fix16_quat_t(), as_fix16_vec3_t(), &result);

x = fix16_mul(scale, x);
y = fix16_mul(scale, y);
z = fix16_mul(scale, z);
return fix16_vec3 { result.x, result.y, result.z };
}

fix16_vec3_t fix16_vec3_t::reflect(const fix16_vec3_t& v, const fix16_vec3_t& normal) {
// TODO: Move this to a C function
const fix16_t factor = dot_product(v, normal) << 1;
const fix16_vec3_t proj = normal * factor;
} // namespace yaul

return (v - proj);
}
#endif /* __cplusplus */
2 changes: 1 addition & 1 deletion libyaul/gamemath/fix16/fix16_mat43.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE for details.
*
* Israel Jacquez <[email protected]>
* Romulo Fernandes <[email protected]>
* Romulo Leitao <[email protected]>
*/

#include <string.h>
Expand Down
Loading