Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Vector.h"
- float vec3Length(vec3 v){
- return v.length();
- }
- float vec3Dot(vec3 v){
- return v.dot();
- }
- float vec3Dot(const vec3 a, const vec3 b){
- return a.x*b.x+a.y*b.y+a.z*b.z;
- }
- vec3 vec3Normalize(vec3 v){
- float l = vec3Length(v);
- v.x /= l;
- v.y /= l;
- v.z /= l;
- return v;
- }
- vec3 vec3Cross(const vec3 a, const vec3 b){
- vec3 v;
- v.x = (a.y*b.z)-(a.z*b.y);
- v.y = (a.z*b.x)-(a.x*b.z);
- v.z = (a.x*b.y)-(a.y*b.x);
- return v;
- }
- vec3 vec3Abs(vec3 v){
- return vec3(abs(v.x), abs(v.y), abs(v.z));
- }
- bool vec3HaveEqualComponent(const vec3 a, const vec3 b){
- if(a.x == b.x || a.y == b.y || a.z == b.z){
- return true;
- }
- else{
- return false;
- }
- }
- float vec3Max(vec3 v){
- float dxy = v.x-v.y;
- if(v.x == v.y && v.y == v.z){
- return v.x;
- }
- else if(dxy > 0){
- float dxz = v.x-v.z;
- if(dxz > 0){
- return v.x;
- }
- else{
- return v.z;
- }
- }
- else{
- float dyz = v.y-v.z;
- if(dyz > 0){
- return v.y;
- }
- else{
- return v.z;
- }
- }
- }
- float vec2Dot(const vec2 v){
- return v.x*v.x+v.y*v.y;
- }
- float vec2Dot(const vec2 a, const vec2 b){
- return a.x*b.x+a.y*b.y;
- }
- float vec2Length(vec2 v){
- return sqrtf(vec2Dot(v));
- }
- vec2 vec2Normalize(vec2 v){
- float l = vec2Length(v);
- v.x /= l;
- v.y /= l;
- return v;
- }
- vec2 vec2Abs(vec2 v){
- return vec2(abs(v.x), abs(v.y));
- }
- bool vec2HaveEqualComponent(const vec2 a, const vec2 b){
- if(a.x == b.x || a.y == b.y){
- return true;
- }
- else{
- return false;
- }
- }
- float vec2Max(vec2 v){
- float d = v.x-v.y;
- if(d == 0){
- return v.x;
- }
- else if(d > 0){
- return v.x;
- }
- else{
- return v.y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement