//for only world void UITextBox::setFace(vector3 right, vector3 down){ right.normalize(); down.normalize(); direction = right; this->down = down; }
vector3<float> get_rotation_axis(vector3<float> u, vector3<float> v) { u.normalize(); v.normalize(); // fix linear case if (u == v || u == -v) { v[0] += 0.1; v[1] += 0.0; v[2] += 0.1; v.normalize(); } return u.cross(v); }
double get_rotation_angle(vector3<float> u, vector3<float> v) { u.normalize(); v.normalize(); double cosine_theta = u.dot(v); // domain of arccosine is [-1, 1] if (cosine_theta > 1) { cosine_theta = 1; } if (cosine_theta < -1) { cosine_theta = -1; } double angle = acos(cosine_theta); return angle; }
bool OBRing::findCenterAndNormal(vector3 & center, vector3 &norm1, vector3 &norm2) { OBMol *mol= this->_parent; int j= 0; const int nA= this->_path.size(); vector3 tmp; center.Set(0.0,0.0,0.0); norm1.Set(0.0,0.0,0.0); norm2.Set(0.0,0.0,0.0); for (j = 0; j != nA; ++j) { center += (mol->GetAtom(_path[j]))->GetVector(); } center/= double(nA); for (j = 0; j != nA; ++j) { vector3 v1= (mol->GetAtom(_path[j]))->GetVector() - center; vector3 v2= (mol->GetAtom(_path[j+1==nA?0:j+1]))->GetVector() - center; tmp= cross(v1,v2); norm1+= tmp; } norm1/= double(nA); norm1.normalize(); norm2= norm1; norm2 *= -1.0; return(true); }
inline bool computeSDFNormal(const UT_VoxelArrayF *g_col, int iX, int iY, int iZ, vector3 &norm){ //Make sure this is a border cell????? if (g_col->getValue(iX, iY, iZ) <= 0) return false; norm[0] = g_col->getValue(iX-1,iY,iZ) - g_col->getValue(iX+1,iY,iZ); norm[1] = g_col->getValue(iX,iY-1,iZ) - g_col->getValue(iX,iY+1,iZ); norm[2] = g_col->getValue(iX,iY,iZ-1) - g_col->getValue(iX,iY,iZ+1); norm.normalize(); return true; }
void matrix4::initialize_camera(vector3 forward, vector3 up) { forward.normalize(); vector3 f = forward; up.normalize(); vector3 r = up; r.normalize(); r.cross_product(f); vector3 u = f; u.cross_product(r); initialize_identity(); set_at(0, 0, r.get_x()); set_at(0, 1, r.get_y()); set_at(0, 2, r.get_z()); set_at(1, 0, u.get_x()); set_at(1, 1, u.get_y()); set_at(1, 2, u.get_z()); set_at(2, 0, f.get_x()); set_at(2, 1, f.get_y()); set_at(2, 2, f.get_z()); }
Wall::Wall(vector3 pos, vector3 dir, vector3 vertex1, vector3 vertex2, vector3 vertex3, vector3 vertex4, string texture_path): LevelDelimiter(pos,dir.normalize(),vector3(0.0,1.0,0.0),vertex1,vertex2,vertex3,vertex4,texture_path) { const_term = dir[0]*vertices[0]+dir[1]*vertices[1]+dir[2]*vertices[2]; square_root = sqrt(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2]); build_bounding_box(); GLfloat orizzontal = ((int)length)/2; GLfloat vertical = ((int)height)/5; GLfloat texc[8] = { 0.0,0.0, orizzontal,0.0, orizzontal,vertical, 0.0,vertical}; memcpy(texcoords, texc, sizeof(GLfloat)*8); }
// LineSearch // // atom: coordinates of atom at iteration k (x_k) // direction: search direction ( d = -grad(x_0) ) // // ALGORITHM: // // step = 1 // for (i = 1 to 100) { max steps = 100 // e_k = energy(x_k) energy of current iteration // x_k = x_k + step * d update coordinates // e_k+1 = energy(x_k+1) energy of next iteration // // if (e_k+1 < e_k) // step = step * 1.2 increase step size // if (e_k+1 > e_k) { // x_k = x_k - step * d reset coordinates to previous iteration // step = step * 0.5 reduce step size // } // if (e_k+1 == e_k) // end convergence criteria reached, stop // } vector3 OBForceField::LineSearch(OBAtom *atom, vector3 &direction) { double e_n1, e_n2, step; vector3 old_xyz, orig_xyz, xyz_k, dir(0.0, 0.0, 0.0); step = 0.2; direction.normalize(); orig_xyz = atom->GetVector(); e_n1 = Energy(false); // calculate e_k unsigned int i; for (i=0; i<100; i++) { old_xyz = atom->GetVector(); xyz_k = atom->GetVector() + direction*step; atom->SetVector(xyz_k); // update coordinates e_n2 = Energy(false); // calculate e_k+1 // convergence criteria, this is 10 times the default convergence // of SteepestDescent or ConjugateGradients. A higher precision here // only takes longer with the same result. if (IsNear(e_n2, e_n1, 1.0e-7)) break; if (e_n2 > e_n1) { // decrease stepsize step *= 0.5; atom->SetVector(old_xyz); } if (e_n2 < e_n1) { // increase stepsize e_n1 = e_n2; step *= 1.2; if (step > 1.0) step = 1.0; } } //cout << "LineSearch steps: " << i << endl; dir = atom->GetVector() - orig_xyz; atom->SetVector(orig_xyz); // cutoff accuracy if (dir.length() < 1.0e-8) return VZero; return dir; }
void quater::toAxisAngle(vector3& axis, double& angle) const { /* #ifdef USE_D3DFUNC buggy.-.- D3DXQuaternionToAxisAngle(*this, axis, &angle); #else */ vector3 log; log.ln(*this); axis.normalize(log); angle=log.length()*2.f; //#endif }
void Scene::inverse_kinematics(vector3 pos, vector3 normal, float &a1, float &a2, float &a3, float &a4, float &a5) { float l1 = .91f, l2 = .81f, l3 = .33f, dy = .27f, dz = .26f; normal.normalize(); vector3 pos1 = pos + normal * l3; float e = sqrtf(pos1.z*pos1.z + pos1.x*pos1.x - dz*dz); a1 = atan2(pos1.z, -pos1.x) + atan2(dz, e); vector3 pos2(e, pos1.y - dy, .0f); a3 = -acosf(min(1.0f, (pos2.x*pos2.x + pos2.y*pos2.y - l1*l1 - l2*l2) / (2.0f*l1*l2))); float k = l1 + l2 * cosf(a3), l = l2 * sinf(a3); a2 = -atan2(pos2.y, sqrtf(pos2.x*pos2.x + pos2.z*pos2.z)) - atan2(l, k); vector3 normal1; normal1 = vector3(RotateRadMatrix44('y', -a1) * vector4(normal.x, normal.y, normal.z, .0f)); normal1 = vector3(RotateRadMatrix44('z', -(a2 + a3)) * vector4(normal1.x, normal1.y, normal1.z, .0f)); a5 = acosf(normal1.x); a4 = atan2(normal1.z, normal1.y); }