mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-07-16 15:54:27 -04:00
CubicVR2: more restricted operators on structures by removing convert-to-pointer. (Fix #550 ?)
This commit is contained in:
Vendored
+13
-7
@@ -12,7 +12,7 @@
|
||||
#include <iostream>
|
||||
#include "vec3.h"
|
||||
#include <cstring>
|
||||
|
||||
#include <stddef.h>
|
||||
namespace CubicVR {
|
||||
|
||||
#define mat3SG(c,x,y) \
|
||||
@@ -20,14 +20,20 @@ namespace CubicVR {
|
||||
c & COMBINE(set,x)(mat3 value) { y = value; return *this; }
|
||||
|
||||
struct mat3 {
|
||||
|
||||
__float a,b,c,d,e,f,g,h,i;
|
||||
|
||||
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
|
||||
#ifndef _WIN32
|
||||
__float& operator [] (unsigned i) { return ((__float *)this)[i]; }
|
||||
#endif
|
||||
operator __float*() const { return (__float *)this; }
|
||||
|
||||
//access as-array:
|
||||
inline __float& operator [] (size_t i) {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
inline const __float& operator [] (size_t i) const {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
mat3(__float ai,__float bi,__float ci,__float di,__float ei,__float fi,__float gi,__float hi,__float ii) {
|
||||
a = ai; b = bi; c = ci; d = di; e = ei; f = fi; g = gi; h = hi; i = ii;
|
||||
};
|
||||
|
||||
Vendored
+32
-9
@@ -15,21 +15,44 @@
|
||||
#include "vec4.h"
|
||||
#include "mat3.h"
|
||||
#include <cmath>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace CubicVR {
|
||||
using namespace std;
|
||||
#define mat4SG(c,x,y) \
|
||||
mat4 COMBINE(get,x)() { return y; } \
|
||||
c & COMBINE(set,x)(mat4 value) { y = value; return *this; }
|
||||
|
||||
struct mat4 {
|
||||
__float a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;
|
||||
|
||||
//16 elements
|
||||
__float a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p;
|
||||
|
||||
//access as-array:
|
||||
inline __float& operator [] (size_t i) {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
|
||||
#ifndef _WIN32
|
||||
__float& operator [] (unsigned i) { return ((__float *)this)[i]; }
|
||||
#endif
|
||||
inline const __float& operator [] (size_t i) const {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
//compare to ZERO-filled matrix
|
||||
inline operator bool() const {
|
||||
|
||||
return (a != 0.0f || b != 0.0f || c != 0.0f || d != 0.0f ||
|
||||
e != 0.0f || f != 0.0f || g != 0.0f || h != 0.0f ||
|
||||
i != 0.0f || j != 0.0f || k != 0.0f || l != 0.0f ||
|
||||
m != 0.0f || n != 0.0f || o != 0.0f || p != 0.0f);
|
||||
}
|
||||
|
||||
//To be accessed by GL API directly, accessed by pointer.
|
||||
//operator* overloading is way too dangerous, especially in ptr != NULL
|
||||
//tests.
|
||||
inline float* to_ptr() const { return (__float *)this; }
|
||||
|
||||
operator __float*() const { return (__float *)this; }
|
||||
mat4(__float ai,__float bi,__float ci,__float di,__float ei,__float fi,__float gi,__float hi,__float ii,__float ji,__float ki,__float li,__float mi,__float ni,__float oi,__float pi) {
|
||||
a = ai; b = bi; c = ci; d = di; e = ei; f = fi; g = gi; h = hi; i = ii; j = ji; k = ki; l = li; m = mi; n = ni; o = oi; p = pi;
|
||||
}
|
||||
@@ -263,15 +286,15 @@ namespace CubicVR {
|
||||
static mat4 transform(vec3 position, vec3 rotation, vec3 scale) {
|
||||
mat4 m = mat4::identity();
|
||||
|
||||
if (position!=NULL) {
|
||||
if (!position) {
|
||||
m *= mat4::translate(position[0],position[1],position[2]);
|
||||
}
|
||||
if (rotation!=NULL) {
|
||||
if (!rotation) {
|
||||
if (!(rotation[0] == 0 && rotation[1] == 0 && rotation[2] == 0)) {
|
||||
m *= mat4::rotate(rotation[0],rotation[1],rotation[2]);
|
||||
}
|
||||
}
|
||||
if (scale!=NULL) {
|
||||
if (!scale) {
|
||||
if (!(scale[0] == 1 && scale[1] == 1 && scale[2] == 1)) {
|
||||
m *= mat4::scale(scale[0],scale[1],scale[2]);
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -88,10 +88,10 @@ namespace CubicVR {
|
||||
m_cache.clear();
|
||||
c_stack = 0;
|
||||
valid = 0;
|
||||
delete result;
|
||||
|
||||
result = mat4::identity();
|
||||
|
||||
if (init_mat != NULL) {
|
||||
if (!init_mat) {
|
||||
m_stack[0] = init_mat;
|
||||
} else {
|
||||
setIdentity();
|
||||
|
||||
Vendored
+15
-7
@@ -12,6 +12,7 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include "cubic_types.h"
|
||||
#include <stddef.h>
|
||||
|
||||
namespace CubicVR {
|
||||
#define vec2SG(c,x,y) \
|
||||
@@ -20,20 +21,27 @@ namespace CubicVR {
|
||||
|
||||
struct vec2 {
|
||||
__float x, y;
|
||||
|
||||
public:
|
||||
__float& u() { return x; }
|
||||
__float& v() { return y; }
|
||||
|
||||
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
|
||||
#ifndef _WIN32
|
||||
__float& operator [] (unsigned i) { return ((__float *)this)[i]; }
|
||||
#endif
|
||||
//access as-array:
|
||||
inline __float& operator [] (size_t i) {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
inline const __float& operator [] (size_t i) const {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
vec2 (__float xi,__float yi) { x = xi; y = yi; }
|
||||
vec2 () { x = y = 0.0f; }
|
||||
|
||||
operator __float*() const { return (__float *)this; }
|
||||
|
||||
|
||||
vec2 operator*(__float v) { return vec2( x*v, y*v ); }
|
||||
|
||||
// vec2 operator*(vec2 v) { return vec2::cross(*this,v); }
|
||||
vec2 operator+(vec2 v) { return vec2::add(*this,v); }
|
||||
vec2 operator-(vec2 v) { return vec2::subtract(*this,v); }
|
||||
|
||||
Vendored
+18
-6
@@ -12,6 +12,7 @@
|
||||
#include <iostream>
|
||||
#include "cubic_types.h"
|
||||
#include <cmath>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace CubicVR {
|
||||
|
||||
@@ -23,19 +24,30 @@ namespace CubicVR {
|
||||
struct vec3 {
|
||||
__float x,y,z;
|
||||
|
||||
operator __float*() const { return (__float *)this; }
|
||||
|
||||
__float& r() { return x; }
|
||||
__float& g() { return y; }
|
||||
__float& b() { return z; }
|
||||
|
||||
#ifndef _WIN32
|
||||
__float& operator [] (unsigned i) { return ((__float *)this)[i]; }
|
||||
#endif
|
||||
//access as-array:
|
||||
inline __float& operator [] (size_t i) {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
inline const __float& operator [] (size_t i) const {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
//compare to ZERO-filled vector
|
||||
inline operator bool() const {
|
||||
|
||||
return (x != 0.0f || y != 0.0f || z != 0.0f);
|
||||
}
|
||||
|
||||
vec3 (__float xi,__float yi,__float zi) { x = xi; y = yi; z = zi; }
|
||||
vec3 () { x = y = z = 0.0f; }
|
||||
|
||||
|
||||
vec3 operator*(__float v) { return vec3(x*v, y*v, z*v); }
|
||||
vec3 operator*(vec3 v) { return vec3::cross(*this,v); }
|
||||
vec3 operator+(vec3 v) { return vec3::add(*this,v); }
|
||||
|
||||
Vendored
+14
-7
@@ -12,6 +12,7 @@
|
||||
#include <iostream>
|
||||
#include "cubic_types.h"
|
||||
#include <cmath>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace CubicVR {
|
||||
|
||||
@@ -20,23 +21,29 @@ namespace CubicVR {
|
||||
c & COMBINE(set,x)(vec3 value) { y = value; return *this; }
|
||||
|
||||
struct vec4 {
|
||||
__float x,y,z,w;
|
||||
|
||||
__float x, y, z, w;
|
||||
|
||||
public:
|
||||
__float& r() { return x; }
|
||||
__float& g() { return y; }
|
||||
__float& b() { return z; }
|
||||
__float& a() { return w; }
|
||||
|
||||
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
|
||||
#ifndef _WIN32
|
||||
__float& operator [] (unsigned i) { return ((__float *)this)[i]; }
|
||||
#endif
|
||||
//access as-array:
|
||||
inline __float& operator [] (size_t i) {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
inline const __float& operator [] (size_t i) const {
|
||||
__float* as_array = (__float*)this;
|
||||
return (as_array[i]);
|
||||
}
|
||||
|
||||
vec4 (__float xi,__float yi,__float zi,__float wi) { x = xi; y = yi; z = zi; w = wi; }
|
||||
vec4 () { x = y = z = w = 0.0f; }
|
||||
|
||||
operator __float*() const { return (__float *)this; }
|
||||
|
||||
vec4 operator*(__float v) { return vec4(x*v, y*v, z*v, w*v); }
|
||||
// vec4 operator*(vec4 v) { return vec4::cross(*this,v); }
|
||||
// vec4 operator+(vec4 v) { return vec4::add(*this,v); }
|
||||
|
||||
Reference in New Issue
Block a user