📄 glvector.cpp
字号:
/*
glvector.cpp - Vector class
Copyright (c) HalfLucifer, 2001.6.12
*/
#include "glvector.h"
float GLvector::Length()
{
double length = (v[0] * v[0]) + (v[1] * v[1]) + (v[2] * v[2]);
return (float) sqrt(length);
}
void GLvector::Normalize()
{
float length, len = 0;
length = Length();
if (length == 0)
return;
len = 1.0f / length;
v[0] *= len;
v[1] *= len;
v[2] *= len;
}
void GLvector::CrossProduct(const GLvector &p, const GLvector &q)
{
v[0] = (p.v[1] * q.v[2]) - (p.v[2] * q.v[1]);
v[1] = (p.v[2] * q.v[0]) - (p.v[0] * q.v[2]);
v[2] = (p.v[0] * q.v[1]) - (p.v[1] * q.v[0]);
}
void GLvector::Clamp(float min, float max)
{
if (v[0] > max || v[0] < min)
v[0] = 0;
if (v[1] > max || v[1] < min)
v[1] = 0;
if (v[2] > max || v[2] < min)
v[2] = 0;
}
void GLvector::RotateX(float amnt, GLvector &dest)
{
float s = GLSin(amnt);
float c = GLCos(amnt);
float y = v[1];
float z = v[2];
dest[0] = v[0];
dest[1] = (y * c) - (z * s);
dest[2] = (y * s) + (z * c);
}
void GLvector::RotateY(float amnt, GLvector &dest)
{
float s = GLSin(amnt);
float c = GLCos(amnt);
float x = v[0];
float z = v[2];
dest[0] = (x * c) + (z * s);
dest[1] = v[1];
dest[2] = (z * c) - (x * s);
}
void GLvector::RotateZ(float amnt, GLvector &dest)
{
float s = GLSin(amnt);
float c = GLCos(amnt);
float x = v[0];
float y = v[1];
dest[0] = (x * c) - (y * s);
dest[1] = (y * c) + (x * s);
dest[2] = v[2];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -