Commit 4cfd4c46 authored by Nova's avatar Nova Committed by Jakob Bornecrantz
Browse files

math: Added vec3 math functions

parent f3803f73
......@@ -9,6 +9,7 @@ set(MATH_SOURCE_FILES
math/m_optics.c
math/m_quatexpmap.cpp
math/m_vec2.h
math/m_vec3.h
)
set(OGL_SOURCE_FILES
......
// Copyright 2019-2020, Collabora, Ltd.
// Copyright 2020, Nova King.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief C vec3 math library.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Nova King <technobaboo@gmail.com>
*
* @see xrt_vec3
* @ingroup aux_math
*/
#pragma once
#include "xrt/xrt_defines.h"
#include <math.h>
#ifdef __cplusplus
extern "C" {
#endif
static inline struct xrt_vec3
m_vec3_mul(struct xrt_vec3 l, struct xrt_vec3 r)
{
struct xrt_vec3 ret = {l.x * r.x, l.y * r.y, l.z * r.z};
return ret;
}
static inline struct xrt_vec3
m_vec3_mul_scalar(struct xrt_vec3 l, float r)
{
struct xrt_vec3 ret = {l.x * r, l.y * r, l.z * r};
return ret;
}
static inline struct xrt_vec3
m_vec3_add(struct xrt_vec3 l, struct xrt_vec3 r)
{
struct xrt_vec3 ret = {l.x + r.x, l.y + r.y, l.z + r.z};
return ret;
}
static inline struct xrt_vec3
m_vec3_sub(struct xrt_vec3 l, struct xrt_vec3 r)
{
struct xrt_vec3 ret = {l.x - r.x, l.y - r.y, l.z - r.z};
return ret;
}
static inline struct xrt_vec3
m_vec3_div(struct xrt_vec3 l, struct xrt_vec3 r)
{
struct xrt_vec3 ret = {l.x / r.x, l.y / r.y, l.z / r.z};
return ret;
}
static inline struct xrt_vec3
m_vec3_div_scalar(struct xrt_vec3 l, float r)
{
struct xrt_vec3 ret = {l.x / r, l.y / r, l.z / r};
return ret;
}
static inline float
m_vec3_len(struct xrt_vec3 l)
{
return sqrtf(l.x * l.x + l.y * l.y + l.z * l.z);
}
#ifdef __cplusplus
}
#endif
......@@ -92,6 +92,7 @@ lib_aux_math = static_library(
'math/m_optics.c',
'math/m_quatexpmap.cpp',
'math/m_vec2.h',
'math/m_vec3.h',
),
include_directories: xrt_include,
dependencies: [eigen3],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment