static float get_barometric_altimeter_digital_value (void) { float altimeter_digital_value; if (test_cockpit_instruments) { static float value = 0.0; value += 10.0; if (value > 100000.0) { value = 0.0; } altimeter_digital_value = value; } else { altimeter_digital_value = feet (current_flight_dynamics->barometric_altitude.value); } return (altimeter_digital_value); }
Character::Character(const std::string& name, World* world, const geometry::Point& position, const geometry::AABB& rect, float weight) : Entity(name, world, position, b2_dynamicBody, Entity::Type::Character, (uint16)~Entity::Type::Character), m_world(world), m_id(4) { createFixture("body", rect, weight, 1); geometry::AABB feet(rect.width - 0.1f, rect.height * 0.05f); geometry::Point pos(0, -rect.height / 2); b2Fixture* sens = createFixture("feet", feet, 1, 1, Type::ThisType, Type::ThisCollideWith, pos, true); world->setCallback(this, sens, character_foot_callback, NULL, false); }
b2Body * Level::CreateBody(b2PolygonDef * polyDef, float x, float y) { b2BodyDef bodyDef; bodyDef.fixedRotation = true; bodyDef.position.Set(x, y); b2Body * body = m_b2World->CreateBody(&bodyDef); polyDef->friction = 1.0f; polyDef->restitution = 0.0f; //bodyDef.linearDamping = 100.0f; //bodyDef. b2PolygonDef feet(*polyDef); for (int i = 0; i < 4; ++i) {feet.vertices[i].y -= 0.5f; feet.vertices[i].x *= 0.9f; } //feet.vertices[3].y = polyDef->vertices[0].y; //feet.vertices[2].y = polyDef->vertices[1].y; //feet.vertices[0].y = feet.vertices[3].y += 0.2f; //feet.vertices[1].y = feet.vertices[2].y += 0.2f; //feet.vertices[0].y = feet.vertices[3].y -= 0.3f; //feet.vertices[1].y = feet.vertices[2].y -= 0.3f; feet.isSensor = true; feet.density = 0.0f; feet.filter. std::cout << "1. x " << polyDef->vertices[0].x << "\t y " << polyDef->vertices[0].y << '\n'; ////std::cout << "2. x " << polyDef->vertices[1].x << "\t y " << polyDef->vertices[1].y << '\n'; //std::cout << "3. x " << polyDef->vertices[2].x << "\t y " << polyDef->vertices[2].y << '\n'; //std::cout << "4. x " << polyDef->vertices[3].x << "\t y " << polyDef->vertices[3].y << '\n'; b2Shape * s = body->CreateShape(&feet); // Add the shape to the body. body->CreateShape(polyDef); // Now tell the dynamic body to compute it's mass properties base // on its shape. body->SetMassFromShapes(); return body; }
void lower_leg(float lowerlegangle, float footangle){ matrixPush(ModelView); matrixRotate(ModelView, lowerlegangle, 0, 0, 1); matrixPush(ModelView); matrixScale(ModelView, .9, .9, 1); joint(); matrixPop(ModelView); matrixPush(ModelView); matrixScale(ModelView, 1.8, .8 , 1); arm_segment(); matrixPop(ModelView); matrixTranslate(ModelView, 0, -4.8, 0); feet(footangle); matrixPop(ModelView); }
static void draw_altitude_counter_digits(void) { float x_org = 0.0, y_org = 0.0, x_min, y_min, x_max, y_max; rgb_colour fg_colour; int altitude = (int)(feet(current_flight_dynamics->barometric_altitude.value) / 100.0) % 100; char buffer[20]; x_min = x_org; y_min = y_org; x_max = x_org + ALTITUDE_COUNTER_WIDTH - 0.001; y_max = y_org + ALTITUDE_COUNTER_HEIGHT - 0.001; set_viewport (x_min, y_min, x_max, y_max); set_rgb_colour(fg_colour, 180, 180, 180, 255); set_mono_font_colour(fg_colour); sprintf(buffer, "%02d", altitude); set_mono_font_type (MONO_FONT_TYPE_8X14); set_mono_font_position(13.0, 3.0); print_mono_font_string(buffer); }
// Compute a point a fixed distance ahead along our path. // Returns path index just after point. int CCSBot::FindPathPoint(float aheadRange, Vector *point, int *prevIndex) { // find path index just past aheadRange int afterIndex; // finds the closest point on local area of path, and returns the path index just prior to it Vector close; int startIndex = FindOurPositionOnPath(&close, true); if (prevIndex) *prevIndex = startIndex; if (startIndex <= 0) { // went off the end of the path // or next point in path is unwalkable (ie: jump-down) // keep same point return m_pathIndex; } // if we are crouching, just follow the path exactly if (IsCrouching()) { // we want to move to the immediately next point along the path from where we are now int index = startIndex + 1; if (index >= m_pathLength) index = m_pathLength - 1; *point = m_path[index].pos; // if we are very close to the next point in the path, skip ahead to the next one to avoid wiggling // we must do a 2D check here, in case the goal point is floating in space due to jump down, etc const float closeEpsilon = 20.0f; // 10.0f while ((*point - close).Make2D().IsLengthLessThan(closeEpsilon)) { index++; if (index >= m_pathLength) { index = m_pathLength - 1; break; } *point = m_path[index].pos; } return index; } // make sure we use a node a minimum distance ahead of us, to avoid wiggling while (startIndex < m_pathLength - 1) { Vector pos = m_path[startIndex + 1].pos; // we must do a 2D check here, in case the goal point is floating in space due to jump down, etc const float closeEpsilon = 20.0f; if ((pos - close).Make2D().IsLengthLessThan(closeEpsilon)) { startIndex++; } else { break; } } // if we hit a ladder, stop, or jump area, must stop (dont use ladder behind us) if (startIndex > m_pathIndex && startIndex < m_pathLength && (m_path[startIndex].ladder || (m_path[startIndex].area->GetAttributes() & NAV_JUMP))) { *point = m_path[startIndex].pos; return startIndex; } // we need the point just *ahead* of us if (++startIndex >= m_pathLength) startIndex = m_pathLength - 1; // if we hit a ladder, stop, or jump area, must stop if (startIndex < m_pathLength && (m_path[startIndex].ladder || (m_path[startIndex].area->GetAttributes() & NAV_JUMP))) { *point = m_path[startIndex].pos; return startIndex; } // note direction of path segment we are standing on Vector initDir = m_path[startIndex].pos - m_path[startIndex - 1].pos; initDir.NormalizeInPlace(); Vector feet(pev->origin.x, pev->origin.y, GetFeetZ()); Vector eyes = feet + Vector(0, 0, HalfHumanHeight); float rangeSoFar = 0; // this flag is true if our ahead point is visible bool visible = true; Vector prevDir = initDir; // step along the path until we pass aheadRange bool isCorner = false; int i; for (i = startIndex; i < m_pathLength; i++) { Vector pos = m_path[i].pos; Vector to = pos - m_path[i - 1].pos; Vector dir = to; dir.NormalizeInPlace(); // don't allow path to double-back from our starting direction (going upstairs, down curved passages, etc) if (DotProduct(dir, initDir) < 0.0f) // -0.25f { i--; break; } // if the path turns a corner, we want to move towards the corner, not into the wall/stairs/etc if (DotProduct(dir, prevDir) < 0.5f) { isCorner = true; i--; break; } prevDir = dir; // don't use points we cant see Vector probe = pos + Vector(0, 0, HalfHumanHeight); if (!IsWalkableTraceLineClear(eyes, probe, WALK_THRU_BREAKABLES)) { // presumably, the previous point is visible, so we will interpolate visible = false; break; } // if we encounter a ladder or jump area, we must stop if (i < m_pathLength && (m_path[i].ladder || (m_path[i].area->GetAttributes() & NAV_JUMP))) break; // Check straight-line path from our current position to this position // Test for un-jumpable height change, or unrecoverable fall if (!IsStraightLinePathWalkable(&pos)) { i--; break; } Vector along = (i == startIndex) ? (pos - feet) : (pos - m_path[i - 1].pos); rangeSoFar += along.Length2D(); // stop if we have gone farther than aheadRange if (rangeSoFar >= aheadRange) break; } if (i < startIndex) afterIndex = startIndex; else if (i < m_pathLength) afterIndex = i; else afterIndex = m_pathLength - 1; // compute point on the path at aheadRange if (afterIndex == 0) { *point = m_path[0].pos; } else { // interpolate point along path segment const Vector *afterPoint = &m_path[afterIndex].pos; const Vector *beforePoint = &m_path[afterIndex - 1].pos; Vector to = *afterPoint - *beforePoint; float length = to.Length2D(); float t = 1.0f - ((rangeSoFar - aheadRange) / length); if (t < 0.0f) t = 0.0f; else if (t > 1.0f) t = 1.0f; *point = *beforePoint + t * to; // if afterPoint wasn't visible, slide point backwards towards beforePoint until it is if (!visible) { const float sightStepSize = 25.0f; float dt = sightStepSize / length; Vector probe = *point + Vector(0, 0, HalfHumanHeight); while (t > 0.0f && !IsWalkableTraceLineClear(eyes, probe, WALK_THRU_BREAKABLES)) { t -= dt; *point = *beforePoint + t * to; } if (t <= 0.0f) *point = *beforePoint; } } // if position found is too close to us, or behind us, force it farther down the path so we don't stop and wiggle if (!isCorner) { const float epsilon = 50.0f; Vector2D toPoint; toPoint.x = point->x - pev->origin.x; toPoint.y = point->y - pev->origin.y; if (DotProduct(toPoint, initDir.Make2D()) < 0.0f || toPoint.IsLengthLessThan(epsilon)) { int i; for (i = startIndex; i < m_pathLength; i++) { toPoint.x = m_path[i].pos.x - pev->origin.x; toPoint.y = m_path[i].pos.y - pev->origin.y; if (m_path[i].ladder || (m_path[i].area->GetAttributes() & NAV_JUMP) || toPoint.IsLengthGreaterThan(epsilon)) { *point = m_path[i].pos; startIndex = i; break; } } if (i == m_pathLength) { *point = GetPathEndpoint(); startIndex = m_pathLength - 1; } } } // m_pathIndex should always be the next point on the path, even if we're not moving directly towards it return startIndex; }
// Return the closest point to our current position on our current path // If "local" is true, only check the portion of the path surrounding m_pathIndex. int CCSBot::FindOurPositionOnPath(Vector *close, bool local) const { if (!HasPath()) return -1; Vector along, toFeet; Vector feet(pev->origin.x, pev->origin.y, GetFeetZ()); Vector eyes = feet + Vector(0, 0, HalfHumanHeight); // in case we're crouching Vector pos; const Vector *from, *to; real_t length; float closeLength; float closeDistSq = 9999999999.9; int closeIndex = -1; real_t distSq; int start, end; if (local) { start = m_pathIndex - 3; if (start < 1) start = 1; end = m_pathIndex + 3; if (end > m_pathLength) end = m_pathLength; } else { start = 1; end = m_pathLength; } for (int i = start; i < end; i++) { from = &m_path[i - 1].pos; to = &m_path[i].pos; // compute ray along this path segment along = *to - *from; // make it a unit vector along the path length = along.NormalizeInPlace(); // compute vector from start of segment to our point toFeet = feet - *from; // find distance of closest point on ray closeLength = DotProduct(toFeet, along); // constrain point to be on path segment if (closeLength <= 0.0f) pos = *from; else if (closeLength >= length) pos = *to; else pos = *from + closeLength * along; distSq = (pos - feet).LengthSquared(); // keep the closest point so far if (distSq < closeDistSq) { // don't use points we cant see Vector probe = pos + Vector(0, 0, HalfHumanHeight); if (!IsWalkableTraceLineClear(eyes, probe, WALK_THRU_EVERYTHING)) continue; // don't use points we cant reach if (!IsStraightLinePathWalkable(&pos)) continue; closeDistSq = distSq; if (close) *close = pos; closeIndex = i - 1; } } return closeIndex; }
// Do reflex avoidance movements if our "feelers" are touched void CCSBot::FeelerReflexAdjustment(Vector *goalPosition) { // if we are in a "precise" area, do not do feeler adjustments if (m_lastKnownArea && (m_lastKnownArea->GetAttributes() & NAV_PRECISE)) return; Vector dir(BotCOS(m_forwardAngle), BotSIN(m_forwardAngle), 0.0f); Vector lat(-dir.y, dir.x, 0.0f); const float feelerOffset = (IsCrouching()) ? 15.0f : 20.0f; const float feelerLengthRun = 50.0f; // 100 - too long for tight hallways (cs_747) const float feelerLengthWalk = 30.0f; const float feelerHeight = StepHeight + 0.1f; // if obstacle is lower than StepHeight, we'll walk right over it float feelerLength = (IsRunning()) ? feelerLengthRun : feelerLengthWalk; feelerLength = (IsCrouching()) ? 20.0f : feelerLength; // Feelers must follow floor slope float ground; Vector normal; //m_eyePos = EyePosition(); m_eyePos.x = pev->origin.x + pev->view_ofs.x; m_eyePos.y = pev->origin.y + pev->view_ofs.y; m_eyePos.z = pev->origin.z + pev->view_ofs.z; if (GetSimpleGroundHeightWithFloor(&m_eyePos, &ground, &normal) == false) return; // get forward vector along floor dir = CrossProduct(lat, normal); // correct the sideways vector lat = CrossProduct(dir, normal); Vector feet(pev->origin.x, pev->origin.y, GetFeetZ()); feet.z += feelerHeight; Vector from = feet + feelerOffset * lat; Vector to = from + feelerLength * dir; bool leftClear = IsWalkableTraceLineClear(from, to, WALK_THRU_EVERYTHING); // avoid ledges, too // use 'from' so it doesn't interfere with legitimate gap jumping (its at our feet) // TODO: Rethink this - it causes lots of wiggling when bots jump down from vents, etc /* float ground; if (GetSimpleGroundHeightWithFloor(&from, &ground)) { if (GetFeetZ() - ground > JumpHeight) leftClear = false; } */ if ((cv_bot_traceview.value == 1.0f && IsLocalPlayerWatchingMe()) || cv_bot_traceview.value == 10.0f) { if (leftClear) UTIL_DrawBeamPoints(from, to, 1, 0, 255, 0); else UTIL_DrawBeamPoints(from, to, 1, 255, 0, 0); } from = feet - feelerOffset * lat; to = from + feelerLength * dir; bool rightClear = IsWalkableTraceLineClear(from, to, WALK_THRU_EVERYTHING); /* // avoid ledges, too if (GetSimpleGroundHeightWithFloor(&from, &ground)) { if (GetFeetZ() - ground > JumpHeight) rightClear = false; } */ if ((cv_bot_traceview.value == 1.0f && IsLocalPlayerWatchingMe()) || cv_bot_traceview.value == 10.0f) { if (rightClear) UTIL_DrawBeamPoints(from, to, 1, 0, 255, 0); else UTIL_DrawBeamPoints(from, to, 1, 255, 0, 0); } const float avoidRange = (IsCrouching()) ? 150.0f : 300.0f; // 50.0f : 300.0f if (!rightClear) { if (leftClear) { // right hit, left clear - veer left *goalPosition = *goalPosition + avoidRange * lat; } } else if (!leftClear) { // right clear, left hit - veer right *goalPosition = *goalPosition - avoidRange * lat; } }