📄 vector.cpp
字号:
{ return CalVector(v.x - u.x, v.y - u.y, v.z - u.z);}*/ /*****************************************************************************//** Calculates a scaled vector. * * This operator calculates the vector multiplied by a factor. * * @param v The vector to be scaled. * @param d The factor to multiply the vector with. * * @return The scaled vector. *****************************************************************************//*CalVector operator*(const CalVector& v, float d){ return CalVector(v.x * d, v.y * d, v.z * d);}*/ /*****************************************************************************//** Calculates a scaled vector. * * This operator calculates the vector multiplied by a factor. * * @param d The factor to multiply the vector with. * @param v The vector to be scaled. * * @return The scaled vector. *****************************************************************************//*CalVector operator*(float d, const CalVector& v){ return CalVector(v.x * d, v.y * d, v.z * d);}*/ /*****************************************************************************//** Calculates a scaled vector. * * This operator calculates the vector divided by a factor. * * @param v The vector to be scaled. * @param d The factor to divide the vector with. * * @return The scaled vector. *****************************************************************************//*CalVector operator/(const CalVector& v, float d){ return CalVector(v.x / d, v.y / d, v.z / d);}*/ /*****************************************************************************//** Calculates the dot product of two vectors. * * This operator calculates the dot product of two vectors. * * @param v The first vector. * @param u The second vector. * * @return The dot product of the two vectors. *****************************************************************************//*float operator*(const CalVector& v, const CalVector& u){ return v.x * u.x + v.y * u.y + v.z * u.z;}*/ /*****************************************************************************//** Calculates the vector product of two vectors. * * This operator calculates the vector product of two vectors. * * @param v The first vector. * @param u The second vector. * * @return The vector product of the two vectors. *****************************************************************************//*CalVector operator%(const CalVector& v, const CalVector& u){ return CalVector(v.y * u.z - v.z * u.y, v.z * u.x - v.x * u.z, v.x * u.y - v.y * u.x);}*/ /*****************************************************************************//** Interpolates the vector instance to another vector. * * This function interpolates the vector instance to another vector by a given * factor. * * @param d The blending factor in the range [0.0, 1.0]. * @param v The vector to be interpolated to. *****************************************************************************//*void CalVector::blend(float d, const CalVector& v){ x += d * (v.x - x); y += d * (v.y - y); z += d * (v.z - z);}*/ /*****************************************************************************//** Clears the vector instance. * * This function clears the vector instance. *****************************************************************************//*void CalVector::clear(){ x = 0.0f; y = 0.0f; z = 0.0f;}*/ /*****************************************************************************//** Returns the length of the vector instance. * * This function returns the length of the vector instance. * * @return The length of the vector instance. *****************************************************************************//*float CalVector::length(){ return (float)sqrt(x * x + y * y + z * z);}*/ /*****************************************************************************//** Normalizes the vector instance. * * This function normalizes the vector instance and returns its former length. * * @return The length of the vector instance before normalizing. *****************************************************************************//*float CalVector::normalize(){ // calculate the length of the vector float length; length = (float) sqrt(x * x + y * y + z * z); // normalize the vector x /= length; y /= length; z /= length; return length;}*/ /*****************************************************************************//** Sets new values. * * This function sets new values in the vector instance. * * @param x The x component. * @param y The y component. * @param z The z component. *****************************************************************************//*void CalVector::set(float vx, float vy, float vz){ x = vx; y = vy; z = vz;}*/ /***************************************************************************** * * Functions for the plane class, they don't have real sense outside * bounding box calculation, * *****************************************************************************/ float CalPlane::eval(CalVector &p){ return p.x*a+p.y*b+p.z*c+d;}void CalPlane::setPosition(CalVector &p){ d=-p.x*a-p.y*b-p.z*c;}void CalPlane::setNormal(CalVector &p){ a=p.x; b=p.y; c=p.z; d=-1e32f;};float CalPlane::dist(CalVector &p){ return fabs( (p.x*a+p.y*b+p.z*c+d)/sqrt(a*a+b*b+c*c)) ;}; /*****************************************************************************//** Computes points of a bounding box. * * This function computes the 8 points of a bounding box. * * @param p A pointer to CalVector[8], the 8 points of the bounding box *****************************************************************************/void CalBoundingBox::computePoints(CalVector *p){ CalMatrix m; int i,j,k; for(i=0;i<2;i++) for(j=2;j<4;j++) for(k=4;k<6;k++) { float x,y,z; m.dxdx=plane[i].a;m.dxdy=plane[i].b;m.dxdz=plane[i].c; m.dydx=plane[j].a;m.dydy=plane[j].b;m.dydz=plane[j].c; m.dzdx=plane[k].a;m.dzdy=plane[k].b;m.dzdz=plane[k].c; float det = m.det(); if(det!=0) { m.dxdx=-plane[i].d;m.dxdy=plane[i].b;m.dxdz=plane[i].c; m.dydx=-plane[j].d;m.dydy=plane[j].b;m.dydz=plane[j].c; m.dzdx=-plane[k].d;m.dzdy=plane[k].b;m.dzdz=plane[k].c; x=m.det()/det; m.dxdx=plane[i].a;m.dxdy=-plane[i].d;m.dxdz=plane[i].c; m.dydx=plane[j].a;m.dydy=-plane[j].d;m.dydz=plane[j].c; m.dzdx=plane[k].a;m.dzdy=-plane[k].d;m.dzdz=plane[k].c; y=m.det()/det; m.dxdx=plane[i].a;m.dxdy=plane[i].b;m.dxdz=-plane[i].d; m.dydx=plane[j].a;m.dydy=plane[j].b;m.dydz=-plane[j].d; m.dzdx=plane[k].a;m.dzdy=plane[k].b;m.dzdz=-plane[k].d; z=m.det()/det; p->x=x;p->y=y;p->z=z; } else {p->x=0.0f;p->y=0.0f;p->z=0.0f;} p++; } } //****************************************************************************//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -