/** * Builds something as close to a cube as can get. This needs a * smarter boundary handling code than I have here. For now, goes for * the nearest cube */ void CubeMesh::innerBuildDefaultMesh( const Eref& e, double volume, unsigned int numEntries ) { double approxN = numEntries; approxN = pow( approxN, 1.0 / 3.0 ); unsigned int smaller = floor( approxN ); unsigned int bigger = ceil( approxN ); unsigned int numSide; if ( smaller != bigger ) { numSide = smaller; } else { unsigned int smallerVol = smaller * smaller * smaller; unsigned int biggerVol = bigger * bigger * bigger; if ( numEntries - smallerVol < biggerVol - numEntries ) numSide = smaller; else numSide = bigger; } double side = pow( volume, 1.0 / 3.0 ); vector< double > coords( 9, side ); coords[0] = coords[1] = coords[2] = 0; coords[6] = coords[7] = coords[8] = side / numSide; nx_ = ny_ = nz_ = numSide; setCoords( e, coords ); }
gboolean SludgeGLApplication::on_drawingarea1_scroll_event(GtkWidget *theWidget, GdkEventScroll *theEvent) { float deltaY; if (theEvent->direction == GDK_SCROLL_UP) { deltaY = -1.; } if (theEvent->direction == GDK_SCROLL_DOWN) { deltaY = 1.; } double x1, y1; int local_pointx, local_pointy; local_pointx = theEvent->x; local_pointy = theEvent->y; x1 = zmul*(local_pointx+x); y1 = -zmul*(local_pointy-y); setZ(z+deltaY); x = -(local_pointx)+x1/zmul; y = (local_pointy)+y1/zmul; setCoords(); render_timer_event(theDrawingarea); return FALSE; }
void gotoCoords(float newX, float newZ, float newO) { /* This is a work-in-progress!!!! This will go to the specified coordinates and rotate to the specified angle, assuming the PID is working correctly. This is a very systematic function, only use when absolutely necessary! */ while (readValues('o') != 90) { // very low tolerance rotateWithOrientation(1, 25); // very slow, and low rotation to insure accuracy } if (newX < x) { while (readValues('x') > newX) moveWithDirection(1, -25); // Low and slow is the way to go! } else if (newX > x) { while (readValues('x') < newX) moveWithDirection(1, -25); } while (readValues('o') != 0) { rotateWithOrientation(1, 25); } if (newZ < z) { while (readValues('z') > newZ) moveWithDirection(1, -25); // Low and slow is the way to go! } else if (newZ > z) { while (readValues('z') < newZ) moveWithDirection(1, -25); } while (readValues('o') != newO) rotateWithOrientation(1, 25); setCoords(newX, newZ, newO); }
void GLImageShader2D::setCoords(QOpenGLBuffer& coords, const GLfloat *offset, int tupleSize, int stride) { coords.bind(); setCoords(offset, tupleSize, stride); coords.release(); }
gboolean SludgeGLApplication::on_drawingarea1_motion_notify_event (GtkWidget *theWidget, GdkEventMotion *theEvent) { refreshStatusbarCursor(theEvent->x, theEvent->y); if ( (awaitButton1Release && theEvent->state & GDK_BUTTON1_MASK) || awaitButton2Release ) { int local_pointx, local_pointy; local_pointx = theEvent->x; local_pointy = theEvent->y; if (theEvent->state & GDK_BUTTON1_MASK) { button1Motion (local_pointx, local_pointy); } else if (awaitButton2Release) { int x1 = x; int y1 = y; x = x1 + (mouseLoc2x - local_pointx); y = y1 + (local_pointy - mouseLoc2y); setCoords(); mouseLoc2x = theEvent->x; mouseLoc2y = theEvent->y; } render_timer_event(theDrawingarea); } gdk_event_request_motions (theEvent); return FALSE; }
void Cannon::shoot() { setCoords(); Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); shotsfired++; }
void Bitmap::setAnchorPoint(float x, float y) { anchorx_ = x; anchory_ = y; if (bitmapdata_ != NULL) { float rx = anchorx_ * (bitmapdata_->width + bitmapdata_->dx1 + bitmapdata_->dx2); float ry = anchory_ * (bitmapdata_->height + bitmapdata_->dy1 + bitmapdata_->dy2); #if 0 dx_ = floor(-rx + 0.5f); dy_ = floor(-ry + 0.5f); #else dx_ = -rx; dy_ = -ry; #endif } else if (texturebase_ != NULL) { float rx = anchorx_ * texturebase_->data->baseWidth; float ry = anchory_ * texturebase_->data->baseHeight; #if 0 dx_ = floor(-rx + 0.5f); dy_ = floor(-ry + 0.5f); // NOTE: -floor(ry + 0.5f) also gives the same result #else dx_ = -rx; dy_ = -ry; #endif } setCoords(); updateBounds(); }
void RectTool::onHandleMoved(const QPointF &pos, int handleFlags) { if (d->selectedLayerInfos.size() != 1) return; auto rectLayer = d->selectedLayerInfos.at(0).rectLayer; if (!rectLayer) return; QPointSet keys; auto rect = rectLayer->rect(); keys |= d->rectKeysWithHandleMargin(rect); auto scenePos = pos * canvas()->transforms()->windowToScene; double left = rect.left(); double right = rect.right(); double top = rect.top(); double bottom = rect.bottom(); if (handleFlags & Left) left = scenePos.x(); if (handleFlags & Right) right = scenePos.x(); if (handleFlags & Top) top = scenePos.y(); if (handleFlags & Bottom) bottom = scenePos.y(); if (right < left) { std::swap(left, right); for (RectHandleItem *handle : d->handles) handle->invertHandleFlagsLeftRight(); } if (bottom < top) { std::swap(top, bottom); for (RectHandleItem *handle : d->handles) handle->invertHandleFlagsTopBottom(); } rect.setCoords(left, top, right, bottom); keys |= d->rectKeysWithHandleMargin(rect); rectLayer->setRect(rect); emit requestUpdate(keys); updateGraphicsItems(); }
inline void Box<T>::scale(T2 xScale, T2 yScale) { T x = static_cast<T>(xScale * getLeft()); T y = static_cast<T>(yScale * getTop()); T x2 = static_cast<T>(xScale * getRight()); T y2 = static_cast<T>(yScale * getBottom()); setCoords(x, y, x2, y2); }
inline void Box<int>::scale(float xScale, float yScale) { int x = static_cast<int>(roundf(xScale * getLeft())); int y = static_cast<int>(roundf(yScale * getTop())); int x2 = static_cast<int>(roundf(xScale * getRight())); int y2 = static_cast<int>(roundf(yScale * getBottom())); setCoords(x, y, x2, y2); }
inline void Box<int>::scale(double xScale, double yScale) { int x = static_cast<int>(round(xScale * getLeft())); int y = static_cast<int>(round(yScale * getTop())); int x2 = static_cast<int>(round(xScale * getRight())); int y2 = static_cast<int>(round(yScale * getBottom())); setCoords(x, y, x2, y2); }
inline void Box<long>::scale(double xScale, double yScale) { long x = static_cast<long>(round(xScale * getLeft())); long y = static_cast<long>(round(yScale * getTop())); long x2 = static_cast<long>(round(xScale * getRight())); long y2 = static_cast<long>(round(yScale * getBottom())); setCoords(x, y, x2, y2); }
void SludgeFloorMaker::prepareOpenGL() { if (! backdrop.total) addSprite(0, &backdrop); z = 0.0; r = g = b = 1.0; zmul = (1.0+z/20); setCoords(); }
void Cannon::reposition(void) { move(canvas()->width()/2-20, canvas()->height()-32); // co ords for barrel of cannon when upright barrelypos = canvas()->height()-32; barrelxpos = canvas()->width()/2; setFrame(index); setCoords(); }
////////////////////////////////////////////////////////////////////////// // Handle events void Menu::eventMouse(const Common::Event &ev) { if (!getFlags()->shouldRedraw) return; bool redraw = true; getFlags()->shouldRedraw = false; // Update coordinates setCoords(ev.mouse); //_mouseFlags = (Common::EventType)(ev.type & Common::EVENT_LBUTTONUP); if (_isShowingCredits) { if (ev.type == Common::EVENT_RBUTTONUP) { showFrame(kOverlayCredits, -1, true); _isShowingCredits = false; } if (ev.type == Common::EVENT_LBUTTONUP) { // Last frame of the credits if (_seqCredits && _creditsSequenceIndex == _seqCredits->count() - 1) { showFrame(kOverlayCredits, -1, true); _isShowingCredits = false; } else { ++_creditsSequenceIndex; showFrame(kOverlayCredits, _creditsSequenceIndex, true); } } } else { // Check for hotspots SceneHotspot *hotspot = NULL; getScenes()->get(getState()->scene)->checkHotSpot(ev.mouse, &hotspot); if (_lastHotspot != hotspot || ev.type == Common::EVENT_LBUTTONUP) { _lastHotspot = hotspot; if (ev.type == Common::EVENT_MOUSEMOVE) { /* todo check event type */ if (!_handleTimeDelta && hasTimeDelta()) setTime(); } if (hotspot) { redraw = handleEvent((StartMenuAction)hotspot->action, ev.type); getFlags()->mouseRightClick = false; getFlags()->mouseLeftClick = false; } else { hideOverlays(); } } } if (redraw) { getFlags()->shouldRedraw = true; askForRedraw(); } }
void SPCtrlCurve::setCoords( gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3 ) { Geom::Point q0( x0, y0 ); Geom::Point q1( x1, y1 ); Geom::Point q2( x2, y2 ); Geom::Point q3( x3, y3 ); setCoords( q0, q1, q2, q3 ); }
void SludgeGLApplication::reshape() { if (! w) x = 0; else x -= (theDrawingarea->allocation.width-w)/2; if (! h) y = 0; else y += (theDrawingarea->allocation.height-h)/2; h = theDrawingarea->allocation.height; w = theDrawingarea->allocation.width; glViewport (0, 0, w, h); setCoords(); }
void SludgeZBufferMaker::prepareOpenGL() { if (! backdrop.total) { addSprite(0, &backdrop); backdrop.sprites[0].width = 640; backdrop.sprites[0].height = 480; } else loadZTextures(&backdrop); z = 0.0; zmul = (1.0+z/20); setCoords(); }
void CylMesh::innerBuildDefaultMesh( const Eref& e, double volume, unsigned int numEntries ) { /// Single voxel cylinder with diameter = length. /// vol = volume = pi.r^2.len. /// So len = 2r, volume = pi*r^2*2r = 2pi*r^3 so r = (volume/2pi)^(1/3) double r = pow( ( volume / ( PI * 2 ) ), 1.0 / 3 ); vector< double > coords( 9, 0 ); coords[3] = 2 * r; coords[6] = r; coords[7] = r; coords[8] = 2 * r / numEntries; setCoords( e, coords ); }
MapDonutRoom::MapDonutRoom(Map& m, PropertyDictionary const& s, GeoVector vec) : MapFeature{ m, s, vec } { unsigned int num_tries = 0; unsigned int minWidth = s.get("min_width", 7); unsigned int maxWidth = s.get("max_width", 20); unsigned int minHeight = s.get("min_height", 7); unsigned int maxHeight = s.get("max_height", 20); unsigned int min_hole_size = s.get("min_hole_size", 5); unsigned int max_retries = s.get("max_retries", 500); std::string floorMaterial = s.get("floor_type", "Dirt"); std::string wallMaterial = s.get("wall_type", "Stone"); IntVec2& starting_coords = vec.start_point; Direction& direction = vec.direction; while (num_tries < max_retries) { sf::IntRect rect; rect.width = the_RNG.pick_uniform(minWidth, maxWidth); rect.height = the_RNG.pick_uniform(minHeight, maxHeight); if (direction == Direction::North) { int offset = the_RNG.pick_uniform(0, rect.width - 1); rect.top = starting_coords.y - rect.height; rect.left = starting_coords.x - offset; } else if (direction == Direction::South) { int offset = the_RNG.pick_uniform(0, rect.width - 1); rect.top = starting_coords.y + 1; rect.left = starting_coords.x - offset; } else if (direction == Direction::West) { int offset = the_RNG.pick_uniform(0, rect.height - 1); rect.top = starting_coords.y - offset; rect.left = starting_coords.x - rect.width; } else if (direction == Direction::East) { int offset = the_RNG.pick_uniform(0, rect.height - 1); rect.top = starting_coords.y - offset; rect.left = starting_coords.x + 1; } else { throw MapFeatureException("Invalid direction passed to MapDonutRoom constructor"); } if ((getMap().isInBounds({ rect.left - 1, rect.top - 1 })) && (getMap().isInBounds({ rect.left + rect.width, rect.top + rect.height }))) { bool okay = true; okay = doesBoxPassCriterion({ rect.left - 1, rect.top - 1 }, { rect.left + rect.width, rect.top + rect.height }, [&](MapTile& tile) { return !tile.isPassable(); }); // Create the hole location. sf::IntRect hole; int x_hole_left = the_RNG.pick_uniform(rect.left + 1, rect.left + rect.width - 2); int x_hole_right = the_RNG.pick_uniform(rect.left + 1, rect.left + rect.width - 2); int y_hole_top = the_RNG.pick_uniform(rect.top + 1, rect.top + rect.height - 2); int y_hole_bottom = the_RNG.pick_uniform(rect.top + 1, rect.top + rect.height - 2); // Make sure the hole isn't TOO small. // GSL GRUMBLE: WHY does abs() return a signed value?!? if ((static_cast<unsigned int>(abs(x_hole_right - x_hole_left)) < min_hole_size - 1) || (static_cast<unsigned int>(abs(y_hole_bottom - y_hole_top)) < min_hole_size - 1)) { okay = false; } if (x_hole_right < x_hole_left) std::swap(x_hole_left, x_hole_right); if (y_hole_bottom < y_hole_top) std::swap(y_hole_top, y_hole_bottom); if (okay) { // Clear out the box EXCEPT FOR the hole. for (int x_coord = rect.left; x_coord <= rect.left + rect.width - 1; ++x_coord) { for (int y_coord = rect.top; y_coord <= rect.top + rect.height - 1; ++y_coord) { if (!((x_coord >= x_hole_left) && (x_coord <= x_hole_right) && (y_coord >= y_hole_top) && (y_coord <= y_hole_bottom))) { auto& tile = getMap().getTile({ x_coord, y_coord }); tile.setTileType({ "Floor", floorMaterial }, { "OpenSpace" }); } } } setCoords(rect); // Add the surrounding walls as potential connection points. // Horizontal walls... for (int x_coord = rect.left + 1; x_coord <= rect.left + rect.width - 1; ++x_coord) { addGrowthVector(GeoVector(x_coord, rect.top - 1, Direction::North)); addGrowthVector(GeoVector(x_coord, rect.top + rect.height, Direction::South)); } // Vertical walls... for (int y_coord = rect.top + 1; y_coord <= rect.top + rect.height - 1; ++y_coord) { addGrowthVector(GeoVector(rect.left - 1, y_coord, Direction::West)); addGrowthVector(GeoVector(rect.left + rect.width, y_coord, Direction::East)); } // Do the same for the hole walls. // Horizontal walls... for (int x_coord = x_hole_left + 1; x_coord < x_hole_right; ++x_coord) { addGrowthVector(GeoVector(x_coord, y_hole_bottom, Direction::North)); addGrowthVector(GeoVector(x_coord, y_hole_top, Direction::South)); } // Vertical walls... for (int y_coord = y_hole_top + 1; y_coord < y_hole_bottom; ++y_coord) { addGrowthVector(GeoVector(x_hole_right, y_coord, Direction::West)); addGrowthVector(GeoVector(x_hole_left, y_coord, Direction::East)); } /// @todo Put either a door or an open area at the starting coords. /// Right now we just make it an open area. auto& startTile = getMap().getTile(starting_coords); startTile.setTileType({ "Floor", floorMaterial }, { "OpenSpace" }); return; } } ++num_tries; } throw MapFeatureException("Out of tries attempting to make MapDonutRoom"); }
void Entity::setCoords(Vec2d* coords) { setCoords(coords->getX(), coords->getY()); }