vec3
3D vector of floats (positions, directions, colors).
Fields and methods
Members of the struct numarray_stack<T,3>. Most of what you do with a CGP type goes through the free functions listed below.
Fields
T x | First coordinate of the vector. |
T y | Second coordinate of the vector. |
T z | Third coordinate of the vector. |
Methods
numarray_stack() | Builds a vector of size 2, 3 or 4 with all coordinates value-initialized (zero for numbers).5 overloads src |
numarray_stack(T const& x, T const& y, T const& z) | Builds a 3D vector from its coordinates x, y and z. src |
numarray_stack(T const& x, numarray_stack<T,2> const& yz) | Builds a 3D vector from x and a 2D vector giving (y, z). src |
numarray_stack(numarray_stack<T,2> const& xy, T const& z) | Builds a 3D vector from a 2D vector giving (x, y) and z. src |
numarray_stack(T1 const& x, T2 const& y, T3 const& z) | Builds a 3D vector from three coordinates of other types, each converted with T(...). src |
| Number of components N, fixed at compile time. src | |
| Sets the N components to the given value and returns the vector. src | |
| Returns the element at index, bound-checked unless CGP_NO_DEBUG is defined. src | |
| Returns a const reference to the element at the given index, with bound checking unless CGP_NO_DEBUG is defined. src | |
| Returns a const reference to the element at the given index; bound-checked for sizes 2, 3 and 4 (vec2, vec3, vec4) unless CGP_NO_DEBUG is defined, but not checked for the other sizes N. src | |
| Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const reference to the element at the given index, without bound checking. src | |
| Returns a copy of the coordinates (x, y) as a 2D vector (for vec3 and vec4). src | |
| Returns a copy of the coordinates (y, z) as a 2D vector (for vec3 and vec4). src | |
| Returns a copy of the coordinates (x, z) as a 2D vector (for vec3 and vec4). src |
Functions taking a vec3
Construct 18
Documented on another page
camera_frame_look_atCamera frame placed at eye and looking toward center (local -z axis), with its y axis aligned as much as possible with up.onframecurve_primitive_circleClosed circle polyline of the given radius and center in the plane orthogonal to the unit normal, the last sample repeating the first one.onnumarraymesh_primitive_arrowArrow mesh from p0 to p1 made of a cylinder and a cone tip ending at p1, the cone length and radius being multiples of cylinder_radius (4 and 2.5 by default).onmeshmesh_primitive_coneCone mesh of base radius and height, with its base centered at center_of_base and pointing along the unit axis_direction, its base capped by a disc by default; Nu samples around the axis and Nv along the height.onmeshmesh_primitive_cubeAxis-aligned cube mesh of the given center and edge length, made of six independent two-triangle faces with flat normals.onmeshmesh_primitive_cubic_gridHexahedron mesh given by its eight corners, each of its six faces sampled as a regular grid (Nx, Ny, Nz samples along each direction).onmeshmesh_primitive_cylinderCylinder mesh of the given radius around the axis [p0,p1], open by default or capped by two discs if is_closed is true, with normals and uv; Nu samples along the axis and Nv around it.onmeshmesh_primitive_discDisc of the given radius centered at center and orthogonal to normal, made of N vertices on the circle linked to a central vertex, with a constant normal and uv mapping the disc into the unit square.onmeshmesh_primitive_ellipsoidEllipsoid mesh with semi-axes scale.x, scale.y, scale.z centered at center, with normals and uv.onmeshmesh_primitive_frameMesh of the frame f: three arrows of length scale along ux, uy and uz (red, green and blue by default) and a sphere at its origin, the arrow radius being frame_thickness*scale.onmeshmesh_primitive_gridBilinear patch through the four corners p00, p10, p11, p01, sampled as an Nu x Nv grid, with normals and uv; sample (ku,kv) has index kv + Nv*ku and uv (ku/(Nu-1), kv/(Nv-1)).onmeshmesh_primitive_quadrangleQuadrangle through the corners p00, p10, p11, p01, made of the triangles (p00,p10,p11) and (p00,p11,p01), with uv (0,0), (1,0), (1,1), (0,1) at the corners.onmeshmesh_primitive_sphereSphere of the given radius and center sampled in spherical coordinates, Nu samples around the z axis and Nv from the south to the north pole, closed at the poles, with normals and uv.onmeshmesh_primitive_tetrahedronTetrahedron mesh given by its four corners, made of four independent triangles with flat normals.onmeshmesh_primitive_torusTorus mesh of major radius r_max and minor radius r_min, centered at center around the unit axis axis_orientation, with normals and uv.onmeshmesh_primitive_triangleSingle-triangle mesh (p0,p1,p2) with a flat normal.onmeshrotation_axis_angleRotation of a given angle in radians around an axis (normalized internally).onrotation_transformtensor_productOuter product a * transpose(b), as a 3x3 matrix.onmat3
Transform 1
vec3 orthogonal_vector(vec3 const& v)Unit vector orthogonal to v, built from its cross product with a coordinate axis; returns (1,0,0) for a zero vector.
Compute 7
intersection_structure intersection_ray_plane(
vec3 const& ray_origin,
vec3 const& ray_direction,
vec3 const& plane_position,
vec3 const& plane_normal
)Intersection in front of the origin of a ray with a plane given by a point and a normal, invalid if the ray is parallel to the plane.
intersection_structure intersection_ray_sphere(
vec3 const& ray_origin,
vec3 const& ray_direction,
vec3 const& sphere_center,
float sphere_radius
)First intersection in front of the origin of a ray (unit direction expected) with a sphere, with its position and outward normal.
intersection_structure intersection_ray_spheres_closest(
vec3 const& ray_origin,
vec3 const& ray_direction,
numarray<vec3> const& sphere_centers,
float sphere_radius,
int* shape_index = nullptr
)Closest intersection of a ray with a set of spheres of common radius, the index of the hit sphere (or -1) being written to shape_index if given.
float noise_perlin(
vec3 const& p,
int octave = 5,
float persistency = 0.3f,
float frequency_gain = 2.0f
)Fractal 3D noise in [0,1] summing octave layers of simplex noise, each layer scaled in amplitude by persistency and in frequency by frequency_gain (defaults 5, 0.3, 2).
Documented on another page
picking_plane_orthogonal_to_cameraIntersects the camera ray through the screen position (relative coordinates) with the plane through plane_position orthogonal to the front direction of the camera.onvec2rotation_around_centerRigid transform that applies the rotation R around center instead of the origin, mapping p to R(p - center) + center.onrotation_transform
Draw 3
Documented on another page
draw_wireframeDraw the triangle edges of every node of the hierarchy in a flat color (no effect with Emscripten/WebGL).onhierarchy_mesh_drawabledraw_wireframeDraw the triangle edges of a mesh_drawable in a flat color, slightly offset toward the camera (no effect with Emscripten/WebGL).onmesh_drawabledraw_wireframeDraw the triangle edges of a triangles_drawable in a flat color, slightly offset toward the camera (no effect with Emscripten/WebGL).ontriangles_drawable
Convert 2
Access 2
template <typename T, int N, typename INDEX_TYPE>
void check_index_bounds(INDEX_TYPE index, numarray_stack<T,3> const& data)Raises an error if the index is outside [0, 2]; no-op when CGP_NO_DEBUG is defined.
Other 1
Documented on another page
opengl_uniformSend a vec3 uniform to the shader; warns if the uniform is not found and expected is true.onopengl_shader_structure
Functions returning a vec3
Construct 1
vec3 trackball_projection(float x, float y)Point (x,y,z) projected on a virtual trackball: unit sphere near the center, hyperbolic sheet z=1/(2d) beyond a distance 1/sqrt(2).
Compute 2
Documented on another page
camera_ray_directionUnit world-space direction of the ray through a screen position given in normalized device coordinates [-1,1]^2, from the camera frame and the inverse projection matrix.onmat4translation_in_plane3D vector of a 2D translation expressed in the xy plane of the given orientation.onvec2
Access 1
Documented on another page
getRow idx1 as a vector, with the index checked at compile time (static_assert).onmatN
Operators
Show the 13 operators (+, -, *, ==, ...)
operator+
3 overloadsaffine_rt operator+(vec3 const& tr, affine_rt const& T)sourceCopy of the rigid transform with tr added to its translation.
affine_rts operator+(vec3 const& tr, affine_rts const& T)sourceCopy of the transform with tr added to its translation.
frame operator+(vec3 const& tr, frame const& f)sourceCopy of the frame with its position translated by tr.
Documented on another page
operator*Apply the affine transform to a point: rotation * (scaling * scaling_xyz * p) + translation (scaling_xyz stretches the local axes).onaffineoperator*Apply the rigid transform to a point: rotation * p + translation.onaffine_rtoperator*Apply the transform to a point: scaling * (rotation * p) + translation.onaffine_rtsoperator*Vector rotated by the rotation.onrotation_transformoperator+Copy of the rigid transform with tr added to its translation.onaffine_rtoperator+Copy of the transform with tr added to its translation.onaffine_rtsoperator+Copy of the frame with its position translated by tr.onframeoperator-Copy of the rigid transform with tr subtracted from its translation.onaffine_rtoperator-Copy of the transform with tr subtracted from its translation.onaffine_rtsoperator-Copy of the frame with its position translated by -tr.onframe