bool FallDetection::isFall(vec3 accelData, vec3 gyroData) { float orientation_mag = gyroData.length(); history[spot] = accelData.length(); char less_one = spot - 1; if (less_one == -1){ less_one = HISTORY_SIZE - 1; } float change_accel = history[spot] - history[less_one]; //Happy path: straight, fast, forward/backward fall if (orientation_mag >= P_THRESHOLD && change_accel > DELTA_A_THRESHOLD){ return true; } //slower/gradual fall, if you try to break your fall char last_one = spot + 1; if (last_one > HISTORY_SIZE - 1){ last_one = 0; } change_accel = history[spot] - history[last_one]; if (orientation_mag >= P_THRESHOLD && change_accel > DELTA_A_THRESHOLD){ return true; } if (++spot >= HISTORY_SIZE){ spot = 0; } return false; }
double vec3::angle(vec3 v, vec3 w) { double arg = dot(v, w) / (v.length() * w.length()); if (arg > 1.0) arg = 1.0; if (arg < -1.0) arg = -1.0; return acos(arg); }
float AngleBetween(const vec3 &a, const vec3 &b) { float dotProd = a.dotProduct(b); float cosine = dotProd / (a.length() * b.length()); return RadToDeg(acos(cosine)); }
/* origin, to rotate about. Returns a rotation matrix. */ mat4 mat4::rotation3D(float angle, const vec3& axisOfRotation) { /* Convert angle to radians. */ float theta = (float)((PI*angle)/180.0); /* Calculate sine and cosine values */ float co = cos(theta); float si = sin(theta); float t = 1.0f - co; /* Calculate the axis' length and the direction cosines. */ float axisLen = axisOfRotation.length(); float a = (axisOfRotation/axisLen)[0]; float b = (axisOfRotation/axisLen)[1]; float c = (axisOfRotation/axisLen)[2]; /* Create the rotation matrix. */ vec4 row1 = vec4(t * a * a + co, t * a * b - si * c, t * a * c + si * b, 0.0); vec4 row2 = vec4(t * a * b + si * c, t * b * b + co, t * b * c - si * a, 0.0); vec4 row3 = vec4(t * a * c - si * b, t * b * c + si * a, t * c * c + co, 0.0); vec4 row4 = vec4(0, 0, 0, 1); return mat4(row1, row2, row3, row4); }
Camera::Camera( ProjectionType projectionType, const vec3& position, const vec3& dop, const vec3& viewUp, REAL angle, REAL aspect): NameableObject(defaultName()), timestamp(0) //[]---------------------------------------------------[] //| Constructor | //[]---------------------------------------------------[] { this->projectionType = projectionType; this->position = position; distance = dop.length(); if (distance < MIN_DISTANCE) distance = MIN_DISTANCE; directionOfProjection = dop * Math::inverse<REAL>(distance); focalPoint = position + dop; this->viewUp = viewUp; if (angle < MIN_ANGLE) angle = MIN_ANGLE; else if (angle > MAX_ANGLE) angle = MAX_ANGLE; viewAngle = angle; height = 2 * distance * (REAL)tan(Math::toRadians<REAL>(angle) * 0.5); aspectRatio = aspect < MIN_ASPECT ? MIN_ASPECT : aspect; F = (REAL)0.1; B = (REAL)1000.1; viewModified = true; }
void EnvironmentRender::refraction(vec3 pos, vec3 nor, gchandle tex) { kgmCamera cam; vec3 cpos = gr->m_camera->mPos; vec3 cdir = gr->m_camera->mDir; f32 fov = gr->m_camera->mFov; f32 asp = gr->m_camera->mAspect; cam.set(fov, asp, gr->m_camera->mNear, gr->m_camera->mFar, cpos, cdir, vec3(0, 0, 1)); kgmGraphics::Options o; o.width = 512; o.height = 512; o.clipping = true; vec3 inor = nor; inor.normalize(); inor.invert(); o.plane[0] = inor.x; o.plane[1] = inor.y; o.plane[2] = inor.z; o.plane[3] = pos.length(); o.discard = m_discard; gc->gcTexTarget(m_target, tex, gctype_tex2d); gc->gcSetTarget(m_target); gr->render(cam, o); gc->gcSetTarget(null); }
vec3 normalize(const vec3 &v) { float n = v.length(); if (n == 0.0) n = FLT_MIN; return v * (1.0 / n); }
mat3 get2DRotMat(vec3 normal) { mat3 make2DMat = mat3(vec3(1,0,0), vec3(0,1,0), vec3(0,0,1)); vec3 upVect = vec3(0,0,1); if (abs(normal[2]) != 1) { vec3 rotationAxis = (normal ^ upVect).normalize(); double rotationAngle = acos((double)((normal * upVect))/(normal.length()/upVect.length())); make2DMat = getRotationMatrix(rotationAxis, rotationAngle); } return make2DMat; }
void kgmOSL::listener(vec3& pos, vec3& vel, vec3& ort) { float l = vel.length(); float dirort[6] = {vel.x, vel.y, vel.z, ort.x, ort.y, ort.z}; position = pos; velocity = vel; orient = ort; (void)l; (void)dirort; }
void setRay() { vert = vec3(0, 1, 0); hori = vert ^ dir; dir = dir.normalize(); vert = vert.normalize(); hori = hori.normalize(); hori = hori * ( dir.length() * Tan(Fangle/2) / (Rw/2) ); vert = vert * ( dir.length() * Tan(Fangle/2) / (Rh/2) ); dir = dir - Rw/2 * hori + Rh/2 * vert; ///cout << dir[0] << ", " << dir[1] << ", " << dir[2] << endl; }
void tgPose::RotateAxis (vec3 r) { // tgQuaternion q2; // q2.fromEuler(rot.x,rot.y,rot.z); // q = q2 * q; // q.normalise(); tgQuaternion q2; float a = r.length (); r.normalize (); q2.fromAxis (r, a); q = q2 * q; q.normalise (); }
ModelObject::ModelObject(const string& obj_path, const vec3& scale, const string& texture_path, const unsigned int tex_unit) { if (!obj_path.empty() && !texture_path.empty() && (scale.length() != 0)) { ApplicationHelper::load_objectfile(obj_path, vertices, uvs, normals); if (!vertices.empty() && !uvs.empty() && !normals.empty()) { create_modelobject(vertices, uvs, normals); texture_id = ApplicationHelper::load_bmp_texture(texture_path, tex_unit); texture_unit = tex_unit; scale_vector = scale; position = vec3(0.0f, 0.0f, 0.0f); } else throw invalid_argument("The read data as one of vertices, uvs or normals of obj-file is empty."); } else throw invalid_argument("The passed path of obj or texture or the passed scale is empty."); }
static float angle(const vec3& a, const vec3& b) { return acos(vec3::dot(a, b) / (a.length() * b.length())); }
float vec3::angle(const vec3 &b) const { float l = b.length(); return acosf( dot(b)/l ) / l; }
static vec3 normalize (const vec3& input) { float length = input.length(); return (length > 0.0f ? input / length : input); }
double angle(const vec3& vec1, const vec3& vec2) { return acos(dotProduct(vec1,vec2)/vec1.length()/vec2.length()); }
// Compara dos puntos por su modulo bool distanceOrderingFunctions (vec3 p1, vec3 p2) { return (p1.length() < p2.length()); }
double angle(vec3 a, vec3 b){ return ((a.x*b.x) - (a.y*b.y) - (a.z*b.z))/(a.length()*b.length()); }
vec3 normalize(vec3 a){ return a/a.length(); }