22 #ifndef __ND_CUDA_VECTOR_H__
23 #define __ND_CUDA_VECTOR_H__
26 #include <vector_types.h>
27 #include <cuda_runtime.h>
28 #include "ndCudaIntrinsics.h"
45 inline __device__ __host__
ndCudaVector(
float val_x,
float val_y,
float val_z,
float val_w)
74 inline float __device__ __host__ GetElement(
int i)
const
79 inline void __device__ __host__ SetElement(
int i,
float val)
102 cuSelect(x > A.x, 1.0f, 0.0f),
103 cuSelect(y > A.y, 1.0f, 0.0f),
104 cuSelect(z > A.z, 1.0f, 0.0f),
105 cuSelect(w > A.w, 1.0f, 0.0f));
111 cuSelect(x < A.x, 1.0f, 0.0f),
112 cuSelect(y < A.y, 1.0f, 0.0f),
113 cuSelect(z < A.z, 1.0f, 0.0f),
114 cuSelect(w < A.w, 1.0f, 0.0f));
119 return ndCudaVector(cuAbs(x), cuAbs(y), cuAbs(z), cuAbs(w));
129 return ndCudaVector(cuMin(x, A.x), cuMin(y, A.y), cuMin(z, A.z), cuMin(w, A.w));
134 return ndCudaVector(cuMax(x, A.x), cuMax(y, A.y), cuMax(z, A.z), cuMax(w, A.w));
139 return ndCudaVector(cuFloor(x), cuFloor(y), cuFloor(z), cuFloor(w));
142 inline ndCudaVector __device__ __host__ Scale(
float s)
const
147 inline float __device__ __host__ AddHorizontal()
const
149 return x + y + z + w;
152 inline float __device__ __host__ DotProduct(
const ndCudaVector& B)
const
154 return (*
this * B).AddHorizontal();
165 inline ndCudaVector __device__ __host__ Normalize()
const
167 float den = 1.0f / sqrtf(DotProduct(*
this));
168 return ndCudaVector(x * den, y * den, z * den, w * den);