12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "Vector3D.h"
- #include <math.h>
- void vectorSet(Vector3D* v, float x, float y, float z) {
- v->x = x;
- v->y = y;
- v->z = z;
- }
- void vectorSetTo(Vector3D* v1, Vector3D* v2) {
- v1->x = v2->x;
- v1->y = v2->y;
- v1->z = v2->z;
- }
- void vectorSetToInverse(Vector3D* v1, Vector3D* v2) {
- v1->x = -v2->x;
- v1->y = -v2->y;
- v1->z = -v2->z;
- }
- void vectorSetMul(Vector3D* v1, Vector3D* v2, float f) {
- v1->x = v2->x * f;
- v1->y = v2->y * f;
- v1->z = v2->z * f;
- }
- void vectorSetAngles(Vector3D* v, float lengthAngle, float widthAngle) {
- lengthAngle = lengthAngle * M_PI / 180.0f;
- widthAngle = widthAngle * M_PI / 180.0f;
- v->x = cosf(widthAngle) * sinf(lengthAngle);
- v->z = cosf(widthAngle) * cosf(lengthAngle);
- v->y = sinf(widthAngle);
- }
- void vectorAdd(Vector3D* v1, Vector3D* v2) {
- v1->x += v2->x;
- v1->y += v2->y;
- v1->z += v2->z;
- }
- void vectorSub(Vector3D* v1, Vector3D* v2) {
- v1->x -= v2->x;
- v1->y -= v2->y;
- v1->z -= v2->z;
- }
- void vectorMul(Vector3D* v1, float f) {
- v1->x *= f;
- v1->y *= f;
- v1->z *= f;
- }
- void vectorAddMul(Vector3D* v1, Vector3D* v2, float f) {
- v1->x += v2->x * f;
- v1->y += v2->y * f;
- v1->z += v2->z * f;
- }
- void vectorCross(Vector3D* v, float x, float y, float z) {
- vectorSet(v, v->y * z - v->z * y, v->z * x - v->x * z, v->x * y - v->y * x);
- }
- void vectorCrossWith(Vector3D* v1, Vector3D* v2) {
- vectorSet(v1, v1->y * v2->z - v1->z * v2->y, v1->z * v2->x - v1->x * v2->z, v1->x * v2->y - v1->y * v2->x);
- }
- void vectorNormalize(Vector3D* v) {
- float f = vectorLength(v);
- v->x /= f;
- v->y /= f;
- v->z /= f;
- }
- float vectorLength(Vector3D* v) {
- return sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
- }
- float vectorDot(Vector3D* v1, Vector3D* v2) {
- return v1->x * v2->x + v1->y * v2->y + v1->z * v2->z;
- }
- float vectorDotInverse(Vector3D* v1, Vector3D* v2) {
- return v1->x * (-v2->x) + v1->y * (-v2->y) + v1->z * (-v2->z);
- }
|