3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
3DCoat math/vectors operations

It is easy to operate over vectors/matrices within the 3DCoat API. Of course, look cVec2, cVec3, cVec4, cMat3, cMat4 references. In most cases, the operations are intuitive and semi-obvious. There are several simple examples:
Vectors initialization:

coat::vec3 v(0,1,2); // define the 3d vector
coat::vec3 z(0); // zero vector
coat::vec3 x = coat::vec3::Zero; // other way to get zero vector
coat::vec4 v4(1,2,3,4); // 4D vector
coat::vec4 v41(x,1.0); // get 4D vector from the 3D vector, we insert the missing w component
coat::vec3 v3 = v4.ToVec3(); // convert 4d vector to 3d, we just take x,y,z
comms::cVec3 vec3
3D - float vector, see the cVec3
Definition CoreAPI.h:50
comms::cVec4 vec4
4D - float vector, see the cVec4
Definition CoreAPI.h:47

Vector operations examples:

coat::vec3 c = coat::vec3::Cross(a,b); // cross-product
float dp = a.dot(b); // dot-product
dp = coat::vec3::Dot(a,b);// dot-product
a.Normalize(); // normalization
a = b.ToNormal(); // get normalized vector

Usually, all transforms over the 3D vectors are performed using 4D matrices.

coat::mat4 m = comms::mat4::Scaling(3.0)*comms::mat4::Translation(1,2,3);// transform matrix definition, first, scale 3 times, then translate on (1,2,3)
coat::vec3 x(1,2,3); // 3d vector declaration
x.TransformCoordinate(m); // transform the vector coordinate by the 4D matrix
coat::vec3 n(3,4,5);
n.Normalize(); // normalize vector
n.TransformNormal(m); // transform as vector, pay attention resulting vector is not mandatory normalized
comms::cMat4 mat4
4x4 float matrix, see the cMat4
Definition CoreAPI.h:59