source: trunk/nv/stl/math/cast.hh @ 451

Last change on this file since 451 was 451, checked in by epyon, 10 years ago
  • math library started
File size: 3.5 KB
Line 
1// Copyright (C) 2015-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
6
7/**
8 * @file common.hh
9 * @author Kornel Kisielewicz epyon@chaosforge.org
10 * @brief math casts
11 */
12
13#ifndef NV_STL_MATH_CAST_HH
14#define NV_STL_MATH_CAST_HH
15
16#include <nv/stl/math/common.hh>
17#include <nv/base/capi.hh>
18
19namespace nv
20{
21
22        template < typename T >
23        inline const T* data_cast( const math::tvec2< T >& v )
24        {
25                return &( v.x );
26        }
27
28        template < typename T >
29        inline T* data_cast( math::tvec2< T >& v )
30        {
31                return &( v.x );
32        }
33
34        template < typename T >
35        inline const T* data_cast( const math::tvec3< T >& v )
36        {
37                return &( v.x );
38        }
39
40        template < typename T >
41        inline T* data_cast( math::tvec3< T >& v )
42        {
43                return &( v.x );
44        }
45
46        template < typename T >
47        inline const T* data_cast( const math::tvec4< T >& v )
48        {
49                return &( v.x );
50        }
51
52        template < typename T >
53        inline T* data_cast( math::tvec4< T >& v )
54        {
55                return &( v.x );
56        }
57
58        template < typename T >
59        inline const T* data_cast( const math::tmat2< T >& m )
60        {
61                return &( m[0].x );
62        }
63
64        template < typename T >
65        inline T* data_cast( math::tmat2< T >& m )
66        {
67                return &( m[0].x );
68        }
69
70        template < typename T >
71        inline const T* data_cast( const math::tmat3< T >& m )
72        {
73                return &( m[0].x );
74        }
75
76        template < typename T >
77        inline T* data_cast( math::tmat3< T >& m )
78        {
79                return &( m[0].x );
80        }
81
82        template < typename T >
83        inline const T* data_cast( const math::tmat4< T >& m )
84        {
85                return &( m[0].x );
86        }
87
88        template < typename T >
89        inline T* data_cast( math::tmat4< T >& m )
90        {
91                return &( m[0].x );
92        }
93
94        template < typename T >
95        inline const T* data_cast( const math::tquat< T >& q )
96        {
97                return &( q[0] );
98        }
99
100        template < typename T >
101        inline T* data_cast( math::tquat< T >& q )
102        {
103                return &( q[0] );
104        }
105
106        template < typename T >
107        inline math::tvec2<T> make_vec2( const T * const ptr )
108        {
109                math::tvec2<T> result( math::ctor::uninitialize );
110                nvmemcpy( data_cast( result ), ptr, sizeof( math::tvec2<T> ) );
111                return result;
112        }
113
114        template < typename T >
115        inline math::tvec3<T> make_vec3( const T * const ptr )
116        {
117                math::tvec3<T> result( math::ctor::uninitialize );
118                nvmemcpy( data_cast( result ), ptr, sizeof( math::tvec3<T> ) );
119                return result;
120        }
121
122        template < typename T >
123        inline math::tvec4<T> make_vec4( const T * const ptr )
124        {
125                math::tvec4<T> result( math::ctor::uninitialize );
126                nvmemcpy( data_cast( result ), ptr, sizeof( math::tvec4<T> ) );
127                return result;
128        }
129
130        template < typename T >
131        inline math::tmat2<T> make_mat2( const T * const ptr )
132        {
133                math::tmat2<T> result( math::ctor::uninitialize );
134                nvmemcpy( data_cast( result ), ptr, sizeof( math::tmat2<T> ) );
135                return result;
136        }
137
138        template < typename T >
139        inline math::tmat3<T> make_mat3( const T * const ptr )
140        {
141                math::tmat3<T> result( math::ctor::uninitialize );
142                nvmemcpy( data_cast( result ), ptr, sizeof( math::tmat3<T> ) );
143                return result;
144        }
145
146        template < typename T >
147        inline math::tmat4<T> make_mat4( const T * const ptr )
148        {
149                math::tmat4<T> result( math::ctor::uninitialize );
150                nvmemcpy( data_cast( result ), ptr, sizeof( math::tmat4<T> ) );
151                return result;
152        }
153
154        template < typename T >
155        inline math::tquat<T> make_quat( const T * const ptr )
156        {
157                math::tquat<T> result( math::ctor::uninitialize );
158                nvmemcpy( data_cast( result ), ptr, sizeof( math::tquat<T> ) );
159                return result;
160        }
161
162}
163
164#endif // NV_STL_MATH_COMMON_HH
Note: See TracBrowser for help on using the repository browser.