void FilteredView::keyPressEvent( QKeyEvent* keyEvent ) { bool noModifier = keyEvent->modifiers() == Qt::NoModifier; if ( keyEvent->key() == Qt::Key_BracketLeft && noModifier ) { for ( qint64 i = static_cast<qint64>( getViewPosition() ) - 1; i >= 0; --i ) { if ( lineType( i ) == Marked ) { selectAndDisplayLine( static_cast<LineNumber>( i ) ); break; } } keyEvent->accept(); } else if ( keyEvent->key() == Qt::Key_BracketRight && noModifier ) { for ( qint64 i = getViewPosition() + 1; i < logFilteredData_->getNbLine(); ++i ) { if ( lineType( i ) == Marked ) { selectAndDisplayLine( static_cast<LineNumber>( i ) ); break; } } keyEvent->accept(); } else { keyEvent->ignore(); AbstractLogView::keyPressEvent( keyEvent ); } }
void UIViewport::getViewBounds(Pnt2f& TopLeft, Pnt2f& BottomRight) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); TopLeft.setValues(getViewPosition().x(),getViewPosition().y()); BottomRight = TopLeft + (InsetsBottomRight - InsetsTopLeft); }
bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelDetails& wheel) { if (! (e.mods.isAltDown() || e.mods.isCtrlDown())) { const bool hasVertBar = verticalScrollBar.isVisible(); const bool hasHorzBar = horizontalScrollBar.isVisible(); if (hasHorzBar || hasVertBar) { float wheelIncrementX = wheel.deltaX; float wheelIncrementY = wheel.deltaY; if (wheelIncrementX != 0) { wheelIncrementX *= 14.0f * singleStepX; wheelIncrementX = (wheelIncrementX < 0) ? jmin (wheelIncrementX, -1.0f) : jmax (wheelIncrementX, 1.0f); } if (wheelIncrementY != 0) { wheelIncrementY *= 14.0f * singleStepY; wheelIncrementY = (wheelIncrementY < 0) ? jmin (wheelIncrementY, -1.0f) : jmax (wheelIncrementY, 1.0f); } Point<int> pos (getViewPosition()); if (wheelIncrementX != 0 && wheelIncrementY != 0 && hasHorzBar && hasVertBar) { pos.setX (pos.x - roundToInt (wheelIncrementX)); pos.setY (pos.y - roundToInt (wheelIncrementY)); } else if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar)) { if (wheelIncrementX == 0 && ! hasVertBar) wheelIncrementX = wheelIncrementY; pos.setX (pos.x - roundToInt (wheelIncrementX)); } else if (hasVertBar && wheelIncrementY != 0) { pos.setY (pos.y - roundToInt (wheelIncrementY)); } if (pos != getViewPosition()) { setViewPosition (pos); return true; } } } return false; }
void UIViewport::updateLayout(void) { if(getViewComponent() != NULL) { Vec2f Size(getCorrectedViewSize()); getViewComponent()->editPosition().setValues(-getViewPosition().x(),-getViewPosition().y()); updateViewComponentSize(); produceStateChanged(ChangeEvent::create(UIViewportRefPtr(this), getSystemTime())); } }
/* note that the world coordinates will be the negative value of the array indices */ void collisionResponse() { /* implement collision, gravity, and climbing onto single cubes here */ float x,y,z; getViewPosition(&x,&y,&z); x *= -1; y *= -1; z *= -1; if(flycontrol == 1) return; if(((world[(int)x][(int)y][(int)z] != 0) && (world[(int)x][(int)y][(int)z] != WHITE)) || ((world[(int)x][(int)y+1][(int)z] != 0) && (world[(int)x][(int)y+1][(int)z] != WHITE))) { if(world[(int)x][(int)y+1][(int)z] == 0) { y++; x *= -1; y *= -1; z *= -1; } else { getOldViewPosition(&x,&y,&z); } setViewPosition(x,y,z); } }
void UIViewport::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if(whichField & ViewComponentFieldMask) { clearChildren(); if(getViewComponent() != NULL) { pushToChildren(getViewComponent()); } } if((whichField & ViewSizeFieldMask) && getViewComponent() != NULL) { updateViewComponentSize(); produceStateChanged(ChangeEvent::create(UIViewportRefPtr(this), getSystemTime())); } if((whichField & ViewPositionFieldMask) && getViewComponent() != NULL) { getViewComponent()->editPosition().setValues(-getViewPosition().x(),-getViewPosition().y()); produceStateChanged(ChangeEvent::create(UIViewportRefPtr(this), getSystemTime())); } if((whichField & ViewSizeFieldMask) || (whichField & ViewPositionFieldMask) || (whichField & SizeFieldMask)) { produceStateChanged(ChangeEvent::create(UIViewportRefPtr(this), getSystemTime())); } if(whichField & SizeFieldMask && getViewComponent() != NULL && (getViewComponent()->getScrollableTracksViewportHeight() || getViewComponent()->getScrollableTracksViewportWidth())) { updateViewComponentSize(); } }
bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelDetails& wheel) { if (! (e.mods.isAltDown() || e.mods.isCtrlDown() || e.mods.isCommandDown())) { const bool canScrollVert = (allowScrollingWithoutScrollbarV || verticalScrollBar.isVisible()); const bool canScrollHorz = (allowScrollingWithoutScrollbarH || horizontalScrollBar.isVisible()); if (canScrollHorz || canScrollVert) { const int deltaX = rescaleMouseWheelDistance (wheel.deltaX, singleStepX); const int deltaY = rescaleMouseWheelDistance (wheel.deltaY, singleStepY); Point<int> pos (getViewPosition()); if (deltaX != 0 && deltaY != 0 && canScrollHorz && canScrollVert) { pos.x -= deltaX; pos.y -= deltaY; } else if (canScrollHorz && (deltaX != 0 || e.mods.isShiftDown() || ! canScrollVert)) { pos.x -= deltaX != 0 ? deltaX : deltaY; } else if (canScrollVert && deltaY != 0) { pos.y -= deltaY; } if (pos != getViewPosition()) { if (mouseWheelTimer == nullptr) mouseWheelTimer = new MouseWheelTimer (*this); mouseWheelTimer->startTimer (300); setViewPosition (pos); return true; } } } return false; }
bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelDetails& wheel) { if (! (e.mods.isAltDown() || e.mods.isCtrlDown() || e.mods.isCommandDown())) { const bool canScrollVert = (allowScrollingWithoutScrollbarV || getVerticalScrollBar().isVisible()); const bool canScrollHorz = (allowScrollingWithoutScrollbarH || getHorizontalScrollBar().isVisible()); if (canScrollHorz || canScrollVert) { auto deltaX = rescaleMouseWheelDistance (wheel.deltaX, singleStepX); auto deltaY = rescaleMouseWheelDistance (wheel.deltaY, singleStepY); auto pos = getViewPosition(); if (deltaX != 0 && deltaY != 0 && canScrollHorz && canScrollVert) { pos.x -= deltaX; pos.y -= deltaY; } else if (canScrollHorz && (deltaX != 0 || e.mods.isShiftDown() || ! canScrollVert)) { pos.x -= deltaX != 0 ? deltaX : deltaY; } else if (canScrollVert && deltaY != 0) { pos.y -= deltaY; } if (pos != getViewPosition()) { setViewPosition (pos); return true; } } } return false; }
int send_stuff_to_server() { float px, py, pz, rx, ry, rz; char buf[MESSAGE_LENGTH]; if(player_flag[0]) { player_flag[0] = 0; getViewPosition(&px,&py,&pz); getViewOrientation(&rx,&ry,&rz); sprintf(buf, "player %f %f %f %d %d", px, py, pz, (int)ry, identity); } sendall(server_socket, buf, MESSAGE_LENGTH); sendall(server_socket, "done", MESSAGE_LENGTH); return 0; }
void UIViewport::maximizeVisibility(const Pnt2f& TopLeft, const Pnt2f& BottomRight) { //Scroll as little as possible until as much as can be is visible Pnt2f ViewTopLeft, ViewBottomRight; getViewBounds(ViewTopLeft,ViewBottomRight); Pnt2f NewViewPosition(getViewPosition()); //Vertical if(ViewTopLeft.y() > TopLeft.y()) { //Scroll up NewViewPosition[1] = TopLeft.y(); } else if(ViewBottomRight.y() < BottomRight.y()) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Scroll down NewViewPosition[1] = BottomRight.y() - (InsetsBottomRight - InsetsTopLeft).y(); } //Horizontal if(ViewTopLeft.x() > TopLeft.x()) { //Scroll left NewViewPosition[0] = TopLeft.x(); } else if(ViewBottomRight.x() < BottomRight.x()) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Scroll right NewViewPosition[0] = BottomRight.x() - (InsetsBottomRight - InsetsTopLeft).x(); } setViewPosition(NewViewPosition); }
/* -for assignment 3, mob control and digging goes here */ void update() { float vx, vy, vz, mx, my, mz, rx, ry, rz; // sample_mob_code(); // came with the file; can be replaced static long int last = 0; static int save = 0; static int deg; static int x = 0; static int y = 0; int z = 50; int now; //char buf[MESSAGE_LENGTH]; if(netClient && netServer) fprintf(stderr, "error: client and server at once\n"); if(netClient == 1) { get_stuff_from_server(); send_stuff_to_server(); } if(netServer == 1) { send_stuff_to_clients(); get_stuff_from_client(); } /* check your watch */ now = time(NULL); if((now - last) >= 1) { /* restore a previously saved position */ world[x][y][z] = save; /* calculate position of the light */ x = (WORLDX/2.0)-1+(WORLDX/2.0)*cos(deg*PI/180.0); y = (WORLDY/2.0)-1+(WORLDY/2.0)*sin(deg*PI/180.0); /* save the state of the cube the light will fill */ save = world[x][y][z]; /* place the light and the white cube */ world[x][y][z] = WHITE; /*printf("x, y: %d, %d\n", x, y);*/ setLightPosition(x,y-1,z); sun_flag = 1; /* using this as a timestep for the light and clouds */ deg++; if(deg > 180) deg = 0; /* Every few timesteps, update the clouds */ if((int)deg % 3 == 0) { perlin_clouds(90, 8, deg); clouds_flag = 1; mob_action(); } /* save the time for FPS control */ last = now; } /* sample use of the dig flag, it is set equal to 1 when the user */ /* presses the space bar, you need to reset it to 0 */ if (dig == 1) { digflag[0] = 1; getViewOrientation(&mx,&my,&mz); getViewPosition(&vx,&vy,&vz); vx *= -1; vy *= -1; vz *= -1; while(mx >= 360) mx -= 360; while(my >= 360) my -= 360; while(mz >= 360) mz -= 360; printf("dig: mx, my, mz: %f, %f, %f\t", mx, my, mz); printf("pos: vx, vy, vz: %f, %f, %f\t", vx, vy, vz); rx = vx+sin(my)*cos(mx);//vx+sin(my)*cos(mx) * 1; rz = vz+(-1 * cos(my))*cos(mx);//vz+cos(my)*cos(mx) * 1; ry = vy-sin(mx);//(vy+sin(mx) * 1); printf("got: rx, ry, rz: %f, %f, %f\t", rx, ry, rz); world[(int)round(rx)][(int)round(ry)][(int)round(rz)] = EMPTY; trimout(); // buildDisplayList(); digflag[1] = -1*(int)round(rx); digflag[2] = -1*(int)round(ry); digflag[3] = -1*(int)round(rz); printf("dug: rx, ry, rz: %d, %d, %d\n", -1*(int)round(rx), -1*(int)round(ry), -1*(int)round(rz)); dig = 0; } if(flycontrol == 0) { getViewPosition(&vx,&vy,&vz); vx *= -1; vy *= -1; vz *= -1; if(world[(int)vx][(int)(vy-1.6)][(int)vz] == 0) { vy -= 0.35; vx *= -1; vy *= -1; vz *= -1; setViewPosition(vx,vy,vz); } } /* your code goes here */ }
int send_stuff_to_clients() { float px, py, pz, rx, ry, rz; int i, j; char buf[MESSAGE_LENGTH]; Stack s; new_stack(&s); for(i = 0; i < PLAYER_COUNT; i++) { if(player_flag[i]) { player_flag[i] = 0; if(i == 0) { getViewPosition(&px,&py,&pz); getViewOrientation(&rx,&ry,&rz); sprintf(buf, "player %f %f %f %d %d", px, py, pz, (int)ry, 0); } else { sprintf(buf, "player %f %f %f %d %d", playerPosition[i][0], playerPosition[i][1], playerPosition[i][2], (int)playerPosition[i][3], i); } push(s, buf); } } if(sun_flag) { sun_flag = 0; getLightPosition(&px,&py,&pz); sprintf(buf, "sun %d %d %d", (int)px, (int)py, (int)pz); push(s, buf); } if(clouds_flag) { clouds_flag = 0; for(i = 0; i < WORLDX; i++) for(j = 0; j < WORLDZ; j++) if(world[i][96][j] == WHITE) { sprintf(buf, "cloud %d 90 %d %d", i, j, WHITE); push(s, buf); } } for(i = 0; i < MOB_COUNT; i++) if(mobflag[i]) { mobflag[i] = 0; sprintf(buf, "mob %f %f %f %d %d", mobPosition[i][0], mobPosition[i][1], mobPosition[i][2], (int)mobPosition[i][3], i); push(s, buf); } if(digflag[0]) { digflag[0] = 0; sprintf(buf, "dig %d %d %d", digflag[1], digflag[2], digflag[3]); push(s, buf); } while(pop(s, buf) == 0) { for(i = 0; i < num_clients; i++) { sendall(fdlist[i], buf, MESSAGE_LENGTH); } } sendall(fdlist[i], "done", MESSAGE_LENGTH); kill_stack(&s); return 0; }
void layout(Node* node, ViwePoistionType _type) { if(!node)return; node->setPosition(getViewPosition(_type)); }
void Steering::update() { if (mSteeringEnabled) { if (mUpdateNeeded) { updatePath(); } auto entity = mAvatar.getEntity(); if (!mPath.empty()) { const auto& finalDestination = mPath.back(); auto entity3dPosition = entity->getViewPosition(); const WFMath::Point<2> entityPosition(entity3dPosition.x(), entity3dPosition.z()); //First check if we've arrived at our actual destination. if (WFMath::Distance(WFMath::Point<2>(finalDestination.x(), finalDestination.z()), entityPosition) < 0.1f) { //We've arrived at our destination. If we're moving we should stop. if (mLastSentVelocity.isValid() && mLastSentVelocity != WFMath::Vector<2>::ZERO()) { moveInDirection(WFMath::Vector<2>::ZERO()); } stopSteering(); } else { //We should send a move op if we're either not moving, or we've reached a waypoint, or we need to divert a lot. WFMath::Point<2> nextWaypoint(mPath.front().x(), mPath.front().z()); if (WFMath::Distance(nextWaypoint, entityPosition) < 0.1f) { mPath.pop_front(); nextWaypoint = WFMath::Point<2>(mPath.front().x(), mPath.front().z()); } WFMath::Vector<2> velocity = nextWaypoint - entityPosition; WFMath::Point<2> destination; velocity.normalize(); if (mPath.size() == 1) { //if the next waypoint is the destination we should send a "move to position" update to the server, to make sure that we stop when we've arrived. //otherwise, if there's too much lag, we might end up overshooting our destination and will have to double back destination = nextWaypoint; } //Check if we need to divert in order to avoid colliding. WFMath::Vector<2> newVelocity; bool avoiding = mAwareness.avoidObstacles(entityPosition, velocity * mSpeed, newVelocity); if (avoiding) { auto newMag = newVelocity.mag(); auto relativeMag = mSpeed / newMag; velocity = newVelocity; velocity.normalize(); velocity *= relativeMag; mUpdateNeeded = true; } bool shouldSend = false; if (velocity.isValid()) { if (mLastSentVelocity.isValid()) { //If the entity has stopped, and we're not waiting for confirmation to a movement request we've made, we need to start moving. if (!entity->isMoving() && !mExpectingServerMovement) { shouldSend = true; } else { auto currentTheta = std::atan2(mLastSentVelocity.y(), mLastSentVelocity.x()); auto newTheta = std::atan2(velocity.y(), velocity.x()); //If we divert too much from where we need to go we must adjust. if (std::abs(currentTheta - newTheta) > WFMath::numeric_constants<double>::pi() / 20) { shouldSend = true; } } } else { //If we've never sent a movement update before we should do that now. shouldSend = true; } } if (shouldSend) { //If we're moving to a certain destination and aren't avoiding anything we should tell the server to move to the destination. if (destination.isValid() && !avoiding) { moveToPoint(WFMath::Point<3>(destination.x(), entity3dPosition.y(), destination.y())); } else { moveInDirection(velocity); } } } } else { //We are steering, but the path is empty, which means we can't find any path. If we're moving we should stop movement. //But we won't stop steering; perhaps we'll find a path later. if (mLastSentVelocity.isValid() && mLastSentVelocity != WFMath::Vector<2>::ZERO()) { moveInDirection(WFMath::Vector<2>::ZERO()); } } } }