void LifeForm::move(const LCreal fwd, const LCreal sdws) { if (getDamage() < 1) { osg::Vec3 old = getEulerAngles(); LCreal hdg = old.z(); LCreal tempFwd = fwd, tempSdws = sdws; // our deadband (if we are barely moving, just stop) if (lcAbs(tempFwd) < 0.9f) tempFwd = 0; if (lcAbs(tempSdws) < 0.9f) tempSdws = 0; const double xVel = tempFwd * (lcCos(hdg)); const double yVel = tempFwd * (lcSin(hdg)); // now calculate our sideways velocity const double xxVel = tempSdws * (lcCos((hdg + (90 * static_cast<LCreal>(Basic::Angle::D2RCC))))); const double yyVel = tempSdws * (lcSin((hdg + (90 * static_cast<LCreal>(Basic::Angle::D2RCC))))); // now add the vectors const double newXVel = xVel + xxVel; const double newYVel = yVel + yyVel; LCreal zVel = 0.0; setVelocity(static_cast<LCreal>(newXVel), static_cast<LCreal>(newYVel), zVel); } else setVelocity(0, 0, 0); }
// ----------------------------------------------------------------------- // drawMap() - Called from draw fun, it tells our specific map to draw. // ----------------------------------------------------------------------- void MapDrawer::drawMap(const int zone, const int idx) { if (myMap != 0 && pagers[idx] != 0 && showMap && getDisplay() != 0){ // Update the tiles for the pager pagers[idx]->updateTextures(textureRow[idx], textureCol[idx]); // Set up for drawing lcColor3(mapIntensity, mapIntensity, mapIntensity); glPushMatrix(); // Not centered, move the whole map down the displacement value. if (!getCentered()) { LCreal dis = getOuterRadius(); //LCreal scale = getScale(); LCreal myScale = vpHL / dis; glTranslatef(0, GLfloat(getDisplacement() * myScale), 0); } glTranslatef(0, 0, -0.1f); sinAng = 0.0f; cosAng = 1.0f; // Set the scale, if not the CENTER_PAGER if (idx != CENTER_PAGER) determineScaling(idx); bool nu = getNorthUp(); if (!nu) { GLfloat hdg = (GLfloat) getHeadingDeg(); glRotatef(hdg, 0.0f, 0.0f, 1.0f); sinAng = (LCreal)lcSin(hdg * (LCreal)Basic::Angle::D2RCC); cosAng = (LCreal)lcCos(hdg * (LCreal)Basic::Angle::D2RCC); } // Translate down the pixels first float transPixelX = -pixelCol[idx] * scalingEast[idx]; float transPixelY = pixelRow[idx] * scalingNorth[idx]; // Translate to the next tile glTranslatef(transPixelX, transPixelY, 0.0f); TextureTable& tbl = pagers[idx]->getTable(); int si = tbl.getLowerBoundIndex(); int i1 = si; int i = 0; int lb = 0, ub = 0; // Enable texturing glEnable(GL_TEXTURE_2D); lb = tbl.getLowerBoundIndex(); ub = tbl.getUpperBoundIndex(); for (i = lb; i <= ub; i++) { int j1 = si; for (int j = lb; j <= ub; j++) { drawTexture(i1, j1, idx); j1++; } i1++; } glDisable(GL_TEXTURE_2D); // Done drawing tiles, now draw grid, if selected to draw. if (drawGrid) { i1 = si; for (i = lb; i <= ub; i++) { int j1 = si; for (int j = lb; j <= ub; j++) { goDrawGrid(i1, j1, idx); j1++; } i1++; } } glPopMatrix(); } }
//------------------------------------------------------------------------------ // setSpeed() -- set speed //------------------------------------------------------------------------------ void Worm::setSpeed(const LCreal xx) { speed = xx; dx = lcCos(sangle) * speed; dy = lcSin(sangle) * speed; }
//------------------------------------------------------------------------------ // setStartAngle() -- set starting angle //------------------------------------------------------------------------------ void Worm::setStartAngle(const LCreal radians) { sangle = radians; dx = lcCos(sangle) * speed; dy = lcSin(sangle) * speed; }
//------------------------------------------------------------------------------ // updateData() -- update background data here //------------------------------------------------------------------------------ void Display::updateData(const LCreal dt) { // Get Viewport width and height GLsizei vpWidth = 0; GLsizei vpHeight = 0; getViewportSize(&vpWidth, &vpHeight); // Generate an image when we have the terrain, a view port and we don't have an image if ( terrain != nullptr && terrain->isDataLoaded() && vpWidth > 0 && vpHeight > 0 && image == nullptr) { GLsizei vpWidth = 1024; // default is texture sizes GLsizei vpHeight = 1024; if (!testTexture) { // When not using textures, get the viewport parameters // Get the maximum number of points GLint vpX, vpY; getViewport(&vpX, &vpY, &vpWidth, &vpHeight); // Make sure width is correct for a 4 byte alignment GLsizei w0 = (vpWidth*PIXEL_SIZE); GLsizei w4 = (w0/4)*4; // Truncate to 4 bytes vpWidth = w4/PIXEL_SIZE; } // Allocate the image memory bool ok = initImageMemory(vpWidth, vpHeight); if (ok) { const int NUM_COLUMNS = imgWidth; const int NUM_ROWS = imgHeight; // Allocating space for 'multi-point' tests LCreal* elevations = nullptr; LCreal* aacData = nullptr; bool* validFlgs = nullptr; bool* maskFlgs = nullptr; if (testShadows || testAac || testEarthCurv) { elevations = new LCreal[NUM_ROWS]; aacData = new LCreal[NUM_ROWS]; validFlgs = new bool[NUM_ROWS]; maskFlgs = new bool[NUM_ROWS]; } // Max elevation (Z) value (meters) LCreal maxz = terrain->getMaxElevation(); if (isMaxElevValid()) maxz = getMaxElevation(); // Min elevation (Z) value (meters) LCreal minz = terrain->getMinElevation(); if (isMinElevValid()) minz = getMinElevation(); // Delta altitude (meters) // LCreal deltaElev = maxz - minz + 1; // Compute delta (range of) latitude and longitude double deltaLat = terrain->getLatitudeNE() - terrain->getLatitudeSW(); double deltaLon = terrain->getLongitudeNE() - terrain->getLongitudeSW(); // Compute center position (degs) double cLat = terrain->getLatitudeSW() + deltaLat / 2.0; double cLon = terrain->getLongitudeSW() + deltaLon / 2.0; // Compute distance between points with zoom factor (degs) double spacingLat = deltaLat / NUM_ROWS; double spacingLon = deltaLon / NUM_COLUMNS; // Generate the earth's curvature effect LCreal* curvature =nullptr; if (testEarthCurv) { curvature = new LCreal[NUM_ROWS]; LCreal radius = static_cast<LCreal>(Basic::Nav::ERAD60 * Basic::Distance::NM2M); LCreal maxRng = static_cast<LCreal>(deltaLat * 60.0f * Basic::Distance::NM2M); for (int irow = 0; irow < NUM_ROWS; irow++) { LCreal curRng = maxRng * static_cast<LCreal>(irow)/static_cast<LCreal>(NUM_ROWS); LCreal arc = curRng / radius; LCreal cs = 1.0f; LCreal c0 = lcCos(arc); if (c0 != 0) cs = 1.0f/c0; curvature[irow] = radius * (cs - 1.0f); } } const Basic::Hsva* grayTable[2]; // hue sat value alpha grayTable[0] = new Basic::Hsva( 120.0f, 0.0f, 0.0f, 1.0f ); // black0 grayTable[1] = new Basic::Hsva( 120.0f, 0.0f, 1.0f, 1.0f ); // white0 const Basic::Hsva* colorTable[7]; // hue sat value alpha colorTable[0] = new Basic::Hsva( 240.0f, 1.0f, 1.0f, 1.0f ); // blue colorTable[1] = new Basic::Hsva( 180.0f, 1.0f, 1.0f, 1.0f ); // cyan colorTable[2] = new Basic::Hsva( 120.0f, 1.0f, 1.0f, 1.0f ); // green colorTable[3] = new Basic::Hsva( 60.0f, 1.0f, 1.0f, 1.0f ); // yellow colorTable[4] = new Basic::Hsva( 0.0f, 1.0f, 1.0f, 1.0f ); // red colorTable[5] = new Basic::Hsva( 300.0f, 1.0f, 1.0f, 1.0f ); // magenta colorTable[6] = new Basic::Hsva( 300.0f, 0.05f, 1.0f, 1.0f ); // white0 const Basic::Hsva* greenTable[19]; // hue sat value alpha greenTable[0] = new Basic::Hsva( 120.0f, 1.0f, 0.0f, 1.0f ); greenTable[1] = new Basic::Hsva( 120.0f, 1.0f, 0.0872f, 1.0f ); greenTable[2] = new Basic::Hsva( 120.0f, 1.0f, 0.1736f, 1.0f ); greenTable[3] = new Basic::Hsva( 120.0f, 1.0f, 0.2588f, 1.0f ); greenTable[4] = new Basic::Hsva( 120.0f, 1.0f, 0.3420f, 1.0f ); greenTable[5] = new Basic::Hsva( 120.0f, 1.0f, 0.4226f, 1.0f ); greenTable[6] = new Basic::Hsva( 120.0f, 1.0f, 0.5000f, 1.0f ); greenTable[7] = new Basic::Hsva( 120.0f, 1.0f, 0.5736f, 1.0f ); greenTable[8] = new Basic::Hsva( 120.0f, 1.0f, 0.6428f, 1.0f ); greenTable[9] = new Basic::Hsva( 120.0f, 1.0f, 0.7071f, 1.0f ); greenTable[10] = new Basic::Hsva( 120.0f, 1.0f, 0.7660f, 1.0f ); greenTable[11] = new Basic::Hsva( 120.0f, 1.0f, 0.8192f, 1.0f ); greenTable[12] = new Basic::Hsva( 120.0f, 1.0f, 0.8660f, 1.0f ); greenTable[13] = new Basic::Hsva( 120.0f, 1.0f, 0.9063f, 1.0f ); greenTable[14] = new Basic::Hsva( 120.0f, 1.0f, 0.9397f, 1.0f ); greenTable[15] = new Basic::Hsva( 120.0f, 1.0f, 0.9659f, 1.0f ); greenTable[16] = new Basic::Hsva( 120.0f, 1.0f, 0.9848f, 1.0f ); greenTable[17] = new Basic::Hsva( 120.0f, 1.0f, 0.9962f, 1.0f ); greenTable[18] = new Basic::Hsva( 120.0f, 1.0f, 1.0f, 1.0f ); std::cout << "start image generation" << std::endl; double start = getComputerTime(); for (int icol = 0; icol < NUM_COLUMNS; icol++) { // int halfway = NUM_COLUMNS / 2; // the Lat/long of the southern most point double longitude = cLon + (icol - NUM_COLUMNS/2) * spacingLon; if (testShadows || testAac || testEarthCurv) { for (int irow = 0; irow < NUM_ROWS; irow++) { elevations[irow] = 0; aacData[irow] = 1.0f; validFlgs[irow] = false; maskFlgs[irow] = false; } // the Lat/long of the southern most point double latitude = cLat + (0 - NUM_ROWS/2) * spacingLat; LCreal maxRng = static_cast<LCreal>(deltaLat * 60.0f * Basic::Distance::NM2M); // Direction //LCreal direction = 30.0f * static_cast<LCreal>(icol - NUM_COLUMNS/2)/static_cast<LCreal>(NUM_COLUMNS/2); LCreal direction = 0; // get a strip of elevations from south to north unsigned int num = terrain->getElevations(elevations, validFlgs, NUM_ROWS, latitude, longitude, direction, maxRng, interpolate); // Apply earth curvature effects to terrain elevations if (testEarthCurv) { for (int irow = 0; irow < NUM_ROWS; irow++) { elevations[irow] -= curvature[irow]; } } // Generate Masks if (testShadows) { Basic::Terrain::vbwShadowChecker(maskFlgs, elevations, validFlgs, NUM_ROWS, maxRng, altitude, lookAngle, beamWidth); } // Compute AAC data if (testAac) { //Simulation::Terrain::aac(aacData, elevations, maskFlgs, NUM_ROWS, maxRng, altitude); LCreal angle = static_cast<LCreal>(-10.0f * Basic::Angle::D2RCC); osg::Vec2 vec(lcCos(angle),lcSin(angle)); Basic::Terrain::cLight(aacData, elevations, maskFlgs, NUM_ROWS, maxRng, vec); } } // Draw a line along the Y points (moving from south to north along the latitude lines) for (int irow = 0; irow < NUM_ROWS; irow++) { osg::Vec3 color(0,0,0); LCreal elev = 0; bool valid = false; if (testShadows || testAac || testEarthCurv) { // multi-point test: get the elevation from the array if (validFlgs[irow]) { elev = elevations[irow]; valid = true; } } else { // Single point test: compute the latitude of this point and get the elevation double latitude = cLat + (irow - NUM_ROWS/2) * spacingLat; valid = terrain->getElevation(&elev, latitude, longitude, interpolate); } // If valid and not masked, convert the elevation to a color (or gray) value if (valid && !(testShadows && maskFlgs[irow])) { if (colorScale == GRAY_SCALE) Basic::Terrain::getElevationColor(elev, minz, maxz, grayTable, 2, color); else if (colorScale == COLOR_SCALE) Basic::Terrain::getElevationColor(elev, minz, maxz, colorTable, 7, color); else if (colorScale == GREEN_SCALE) Basic::Terrain::getElevationColor(elev, minz, maxz, greenTable, 19, color); } // Apply AAC data if (valid && testAac) { color = color * aacData[irow]; } //if (icol == 100) { // std::cout << icol << ", " << irow << " = " << elev << " [ " << color.x() << ", " << color.y() << ", " << color.z() << " ]" << std::endl; //} // store this color GLsizei idx = irow*imgWidth*PIXEL_SIZE + icol*PIXEL_SIZE; image[idx+0] = GLubyte( 255.0 * color[0] ); image[idx+1] = GLubyte( 255.0 * color[1] ); image[idx+2] = GLubyte( 255.0 * color[2] ); } } double end = getComputerTime(); double dtime = (end - start); std::cout << "Image finished: time(s) = " << dtime << ", per line(us) = " << (dtime/static_cast<double>(NUM_COLUMNS))*1000000.0 << std::endl; } } BaseClass::updateData(dt); }