int Position::getWidth() const { return getRight() - getLeft() + 1; }
bool TCODBsp::traversePostOrder(ITCODBspCallback *listener,void *userData) { if ( getLeft() && !getLeft()->traversePostOrder(listener,userData)) return false; if ( getRight() && !getRight()->traversePostOrder(listener,userData)) return false; if (!listener->visitNode(this,userData)) return false; return true; }
void WorldTask::logic() { GLFix dx = 0, dz = 0; if(keyPressed(KEY_NSPIRE_8)) //Forward { GLFix dx1, dz1; getForward(&dx1, &dz1); dx += dx1; dz += dz1; } else if(keyPressed(KEY_NSPIRE_2)) //Backward { GLFix dx1, dz1; getForward(&dx1, &dz1); dx -= dx1; dz -= dz1; } if(keyPressed(KEY_NSPIRE_4)) //Left { GLFix dx1, dz1; getRight(&dx1, &dz1); dx -= dx1; dz -= dz1; } else if(keyPressed(KEY_NSPIRE_6)) //Right { GLFix dx1, dz1; getRight(&dx1, &dz1); dx += dx1; dz += dz1; } if(!world.intersect(aabb)) { AABB aabb_moved = aabb; aabb_moved.low_x += dx; aabb_moved.high_x += dx; if(!world.intersect(aabb_moved)) { x += dx; aabb = aabb_moved; } aabb_moved = aabb; aabb_moved.low_z += dz; aabb_moved.high_z += dz; if(!world.intersect(aabb_moved)) { z += dz; aabb = aabb_moved; } aabb_moved = aabb; aabb_moved.low_y += vy; aabb_moved.high_y += vy; can_jump = world.intersect(aabb_moved); if(!can_jump) { y += vy; aabb = aabb_moved; } else if(vy > GLFix(0)) { can_jump = false; vy = 0; } else vy = 0; vy -= 5; in_water = getBLOCK(world.getBlock((x / BLOCK_SIZE).floor(), ((y + eye_pos) / BLOCK_SIZE).floor(), (z / BLOCK_SIZE).floor())) == BLOCK_WATER; if(in_water) can_jump = true; } if(keyPressed(KEY_NSPIRE_5) && can_jump) //Jump { vy = 50; can_jump = false; } if(has_touchpad) { touchpad_report_t touchpad; touchpad_scan(&touchpad); if(touchpad.pressed) { switch(touchpad.arrow) { case TPAD_ARROW_DOWN: xr += speed()/3; break; case TPAD_ARROW_UP: xr -= speed()/3; break; case TPAD_ARROW_LEFT: yr -= speed()/3; break; case TPAD_ARROW_RIGHT: yr += speed()/3; break; case TPAD_ARROW_RIGHTDOWN: xr += speed()/3; yr += speed()/3; break; case TPAD_ARROW_UPRIGHT: xr -= speed()/3; yr += speed()/3; break; case TPAD_ARROW_DOWNLEFT: xr += speed()/3; yr -= speed()/3; break; case TPAD_ARROW_LEFTUP: xr -= speed()/3; yr -= speed()/3; break; } } else if(tp_had_contact && touchpad.contact) { yr += (touchpad.x - tp_last_x) / 50; xr -= (touchpad.y - tp_last_y) / 50; } tp_had_contact = touchpad.contact; tp_last_x = touchpad.x; tp_last_y = touchpad.y; } else { if(keyPressed(KEY_NSPIRE_UP)) xr -= speed()/3; else if(keyPressed(KEY_NSPIRE_DOWN)) xr += speed()/3; if(keyPressed(KEY_NSPIRE_LEFT)) yr -= speed()/3; else if(keyPressed(KEY_NSPIRE_RIGHT)) yr += speed()/3; } //Normalisation required for rotation with nglRotate yr.normaliseAngle(); xr.normaliseAngle(); //xr and yr are normalised, so we can't test for negative values if(xr > GLFix(180)) if(xr <= GLFix(270)) xr = 269; if(xr < GLFix(180)) if(xr >= GLFix(90)) xr = 89; //Do test only on every second frame, it's expensive if(do_test) { GLFix dx = fast_sin(yr)*fast_cos(xr), dy = -fast_sin(xr), dz = fast_cos(yr)*fast_cos(xr); GLFix dist; if(!world.intersectsRay(x, y + eye_pos, z, dx, dy, dz, selection_pos, selection_side, dist, in_water)) selection_side = AABB::NONE; else selection_pos_abs = {x + dx * dist, y + eye_pos + dy * dist, z + dz * dist}; } world.setPosition(x, y, z); do_test = !do_test; if(key_held_down) key_held_down = keyPressed(KEY_NSPIRE_ESC) || keyPressed(KEY_NSPIRE_7) || keyPressed(KEY_NSPIRE_9) || keyPressed(KEY_NSPIRE_1) || keyPressed(KEY_NSPIRE_3) || keyPressed(KEY_NSPIRE_PERIOD) || keyPressed(KEY_NSPIRE_MINUS) || keyPressed(KEY_NSPIRE_PLUS) || keyPressed(KEY_NSPIRE_MENU); else if(keyPressed(KEY_NSPIRE_ESC)) //Save & Exit { save(); Task::running = false; return; } else if(keyPressed(KEY_NSPIRE_7)) //Put block down { if(selection_side != AABB::NONE) { if(!world.blockAction(selection_pos.x, selection_pos.y, selection_pos.z)) { VECTOR3 pos = selection_pos; switch(selection_side) { case AABB::BACK: ++pos.z; break; case AABB::FRONT: --pos.z; break; case AABB::LEFT: --pos.x; break; case AABB::RIGHT: ++pos.x; break; case AABB::BOTTOM: --pos.y; break; case AABB::TOP: ++pos.y; break; default: puts("This can't normally happen #1"); break; } if(!world.intersect(aabb)) { //Only set the block if there's air const BLOCK_WDATA current_block = world.getBlock(pos.x, pos.y, pos.z); if(current_block == BLOCK_AIR || (in_water && getBLOCK(current_block) == BLOCK_WATER)) { if(!global_block_renderer.isOriented(current_inventory.currentSlot())) world.changeBlock(pos.x, pos.y, pos.z, current_inventory.currentSlot()); else { AABB::SIDE side = selection_side; //If the block is not fully oriented and has been placed on top or bottom of another block, determine the orientation by yr if(!global_block_renderer.isFullyOriented(current_inventory.currentSlot()) && (side == AABB::TOP || side == AABB::BOTTOM)) side = yr < GLFix(45) ? AABB::FRONT : yr < GLFix(135) ? AABB::LEFT : yr < GLFix(225) ? AABB::BACK : yr < GLFix(315) ? AABB::RIGHT : AABB::FRONT; world.changeBlock(pos.x, pos.y, pos.z, getBLOCKWDATA(current_inventory.currentSlot(), side)); //AABB::SIDE is compatible to BLOCK_SIDE } //If the player is stuck now, it's because of the block change, so remove it again if(world.intersect(aabb)) world.changeBlock(pos.x, pos.y, pos.z, BLOCK_AIR); } } } } key_held_down = true; } else if(keyPressed(KEY_NSPIRE_9)) //Remove block { if(selection_side != AABB::NONE && world.getBlock(selection_pos.x, selection_pos.y, selection_pos.z) != BLOCK_BEDROCK) world.changeBlock(selection_pos.x, selection_pos.y, selection_pos.z, BLOCK_AIR); key_held_down = true; } else if(keyPressed(KEY_NSPIRE_1)) //Switch inventory slot { current_inventory.previousSlot(); key_held_down = true; } else if(keyPressed(KEY_NSPIRE_3)) { current_inventory.nextSlot(); key_held_down = true; } else if(keyPressed(KEY_NSPIRE_PERIOD)) //Open list of blocks (or take screenshot with Ctrl + .) { if(keyPressed(KEY_NSPIRE_CTRL)) { //Find a filename that doesn't exist char buf[45]; unsigned int i; for(i = 0; i <= 999; ++i) { sprintf(buf, "/documents/ndless/screenshot_%d.ppm.tns", i); struct stat stat_buf; if(stat(buf, &stat_buf) != 0) break; } if(i > 999 || !saveTextureToFile(*screen, buf)) setMessage("Screenshot failed!"); else { sprintf(message, "Screenshot taken (%d)!", i); message_timeout = 20; } } else block_list_task.makeCurrent(); key_held_down = true; } else if(keyPressed(KEY_NSPIRE_MINUS)) //Decrease max view distance { int fov = world.fieldOfView() - 1; world.setFieldOfView(fov < 1 ? 1 : fov); key_held_down = true; } else if(keyPressed(KEY_NSPIRE_PLUS)) //Increase max view distance { world.setFieldOfView(world.fieldOfView() + 1); key_held_down = true; } else if(keyPressed(KEY_NSPIRE_MENU)) { menu_task.makeCurrent(); key_held_down = true; } }
bool Rect::contains(const Vector2 &pt) const { return pt.x > getLeft() && pt.x < getRight() && pt.y < getBottom() && pt.y > getTop(); }
bool Rectangle::contains(const Pos &pos) const { return (pos.x > getLeft()) && (pos.x < getRight()) && (pos.y > getBottom()) && (pos.y < getTop()); }
void cCameraManager::update() { /* TODO: use timeManager.getLastFrameTime().total_milliseconds() */ float move = MOVE; float rot = ROT; Vec3f right = getRight() * move; cKeyManager& keyManager = SimulationState::acquire().getKeyManager(); if(keyManager.isDown(FL_Page_Up)) { m_vecCamPos.y = m_vecCamPos.y + move; m_vecCamLookAt.y = m_vecCamLookAt.y + move; } if(keyManager.isDown(FL_Page_Down)) { m_vecCamPos.y = m_vecCamPos.y - move; m_vecCamLookAt.y = m_vecCamLookAt.y - move; } if(keyManager.isDown(FL_Right)) { m_vecCamPos.x = m_vecCamPos.x + move; m_vecCamLookAt.x = m_vecCamLookAt.x + move; } if(keyManager.isDown(FL_Left)) { m_vecCamPos.x = m_vecCamPos.x - move; m_vecCamLookAt.x = m_vecCamLookAt.x - move; } if(keyManager.isDown(FL_Up)) { m_vecCamPos.z = m_vecCamPos.z - move; m_vecCamLookAt.z = m_vecCamLookAt.z - move; } if(keyManager.isDown(FL_Down)) { m_vecCamPos.z = m_vecCamPos.z + move; m_vecCamLookAt.z = m_vecCamLookAt.z + move; } if(keyManager.isDown('w')) { pitch(-rot); } if(keyManager.isDown('s')) { pitch(rot); } if(keyManager.isDown('a')) { yaw(-rot); } if(keyManager.isDown('d')) { yaw(rot); } if(keyManager.isDown('r')) { roll(-rot); } if(keyManager.isDown('f')) { roll(rot); } if(keyManager.isDown(' ')) { init(); } }
glm::vec3 Camera::getUp() { return glm::normalize(glm::cross(getRight(), getDirection())); }
void CoordinateSystem::moveLeft(double distance) { position -= getRight() * distance; }
void Camera::translateX(const float iDistance){ SCREEN_DECL_METHOD(translateX); _position += (iDistance * getRight()); _viewNeedsUpdate = true; }
// rotation local x void Camera::pitch(const screen::math::Degree& iAngle){ SCREEN_DECL_METHOD(pitch); rotate(getRight(), iAngle); }
//---------------------------------------------------------- glm::vec3 glmRectangle::getTopRight() const { return glm::vec3(getRight(),getTop(),0.); }
int CObject::getWidth() { return (getRight() - getLeft()); }
int CObject::getWCenter() { return (getRight() - getLeft()); }
void CPile::draw(HDC hdc) { /**/itsValueText.setPosition(getItsPosition()); itsCompareText.setPosition(getItsPosition()); itsChangeText.setPosition(getItsPosition()); /* itsValueText.setPosition(getLeft(), getBottom()-20, getRight(), getBottom()); itsCompareText.setPosition(getItsPosition()); itsChangeText.setPosition(getLeft(), getTop()+(getHeight()/2), getRight(), getBottom());*/ int tempValue = int(itsValue*itsMultiply); int tempCompare = int(itsCompareValue*itsMultiply); int tempChange = int(itsChange*itsMultiply); int maxValue; if(itsValue > tempCompare) maxValue = tempValue; else maxValue = tempCompare; double div = 1; if(maxValue > getHeight()) { div = getHeight()/(maxValue*1.1); } int itsVTop = int(div*tempValue); int itsCTop = int(div*tempCompare); int itsCHTop = int(div*tempChange); COLORREF white = RGB(255, 255, 255); COLORREF lightGreen = RGB(100, 200, 100); COLORREF green = RGB(0, 120, 0); COLORREF black = RGB(0, 0, 0); COLORREF red = RGB(255, 0,0); COLORREF orange = RGB(255, 128,0); HBRUSH compareBrush; HBRUSH whiteBrush = CreateSolidBrush(white); HBRUSH greenBrush = CreateSolidBrush(green); HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, whiteBrush); Rectangle(hdc, getLeft(), getTop(), getRight(), getBottom()); HPEN pen = CreatePen(PS_SOLID, 0, green); HPEN oldPen = (HPEN)SelectObject(hdc, pen); SelectObject(hdc, greenBrush); Rectangle(hdc, getLeft()+1, getBottom()-itsVTop, getRight()-1, getBottom()-1); COLORREF compareColor; if(compLarger) { compareColor = lightGreen; } else { if(itsCompareValue > itsValue) compareColor = red; else compareColor = lightGreen; } DeleteObject(pen); pen = CreatePen(PS_SOLID, 0, compareColor); SelectObject(hdc, pen); compareBrush = CreateSolidBrush(compareColor); SelectObject(hdc, compareBrush); if(itsCompareValue != 0) Rectangle(hdc, getLeft()+1, getBottom()-itsCTop, getRight()-1, getBottom()); if(compLarger) { compareColor = lightGreen; if(itsVTop >= getHeight()) itsCHTop = 0; else if((itsVTop+itsCHTop) > getHeight()) itsCHTop = getHeight() - itsVTop; } else { if(itsCompareValue > itsValue) compareColor = red; else compareColor = orange; } DeleteObject(pen); pen = CreatePen(PS_SOLID, 0, compareColor); SelectObject(hdc, pen); DeleteObject(compareBrush); compareBrush = CreateSolidBrush(compareColor); SelectObject(hdc, compareBrush); if((0-itsCHTop) > itsVTop) itsCHTop = (0-itsVTop); if(itsChange != 0) Rectangle(hdc, getLeft()+1, getBottom()-itsCHTop-itsVTop, getRight()-1, getBottom()-itsVTop); DeleteObject(pen); pen = CreatePen(PS_SOLID, 1, black); SelectObject(hdc, pen); MoveToEx(hdc, getLeft(), getBottom()-itsVTop, NULL); LineTo(hdc, getRight(), getBottom()-itsVTop); SelectObject(hdc, oldBrush); SelectObject(hdc, oldPen); DeleteObject(pen); DeleteObject(whiteBrush); DeleteObject(greenBrush); DeleteObject(compareBrush); itsValueText.draw(hdc); if(itsCompareValue != 0) itsCompareText.draw(hdc); if(itsChange != 0) itsChangeText.draw(hdc); //MB(itsValueText.getText()); }
void Camera::shiftRight(const float step) { cameraMatrix = glm::translate(cameraMatrix, getRight() * step); }
void CoordinateSystem::rotateAroundRight(double theta) { Vector3 right = getRight(); forward.rotateArbitrary(right, theta); up.rotateArbitrary(right, theta); }
void Camera::turnDown(const float degrees) { cameraMatrix = glm::rotate(cameraMatrix, -glm::radians(degrees), getRight()); }
void scaleMove(int leftPower, int rightPower, int driveTime) { //vvv determines what direction the motors need to be powered int directionLeft=0; //1 is forward, -1 is reverse int directionRight=0; if (0<leftPower) { directionLeft=1; } if (0>leftPower) { directionLeft=-1; } if (0<rightPower) { directionRight=1; } if (0>rightPower) { directionRight=-1; } int counter=0; //cycle counter if (directionLeft==1) { setLeft(25); //set left motors to 25 power if moving forward } if (directionRight==1) { setRight(25); //set right motors to 25 power } if (directionLeft==-1) { setLeft(-25); } if (directionRight==-1) { setRight(-25); } int stepSize=3; //step size of 3 per 1Msec //vvv if any motor is not at the desired power vvv while(motor[FrontLeft]!=leftPower || motor[FrontRight]!=rightPower || motor[BackLeft]!=leftPower || motor[BackRight]!=rightPower) { //forward section here if(motor[FrontLeft]<leftPower&&directionLeft==1) //if the front left motor is less than desired power, { if(abs(leftPower-motor[FrontLeft])<stepSize) //first check to see if the difference is less than the step size { stepSize=abs(leftPower-motor[FrontLeft]); //change the step size if it is } setLeft(getLeft()+stepSize); //then increase both left motors' power by the step size //motor[FrontLeft]=motor[FrontLeft]+stepSize; //this is the same as what's above ^^^ //motor[BackLeft]=motor[BackLeft]+stepSize; } if(motor[FrontRight]<rightPower&&directionRight==1) //if the frint right motor is less than desired power, { if(abs(rightPower-motor[FrontRight])<3) //first check to see if the difference is less than the step size { stepSize=abs(rightPower-motor[FrontRight]); //change the step size if it is } setRight(getRight()+stepSize); //then increase both the right motors' power by the step size //motor[FrontRight]=motor[FrontLeft]+3; //this is the same as what's above ^^ //motor[BackRight]=motor[BackRight]+3; } //reverse section here if(motor[FrontLeft]>leftPower&&directionLeft==-1) //if the front left motor is more than the desired power, i.e.: 0 when we want -100 { if(abs(leftPower-motor[FrontLeft])<stepSize) //first check to see if the difference is less than the step size { stepSize=abs(leftPower-motor[FrontLeft]); //change the step size if it is } setLeft(getLeft()-stepSize); //then decrease both the left motors by the step size //motor[FrontLeft]=motor[FrontLeft]-stepSize; //this is the same as whats above ^^^ //motor[BackLeft]=motor[BackLeft]-stepSize; } if(motor[FrontRight]>rightPower&&directionRight==-1) //if the front right motor is more than the desired power, i.e.: 0 when we want -100 { if(abs(rightPower-motor[FrontRight])<3) //first check to see if the difference is less than the step size { stepSize=abs(rightPower-motor[FrontRight]); //change the step size if it is } setRight(getRight()-stepSize); //then decrease both the right motors' power by the step size //motor[FrontRight]=motor[FrontLeft]-3; //this is the same as whats above ^^^ //motor[BackRight]=motor[BackRight]-3; } wait1Msec(1); //wait, counter++; //bump the counter up one, } //and repeat until desired power reached if (counter*2>driveTime||counter>=driveTime) { motor[FrontLeft]=0; motor[FrontRight]=0; motor[BackLeft]=0; motor[BackRight]=0; return; } wait1Msec(driveTime-(counter*2)); //subtract the number of ms spent during stepping up, times two for same amount of time stepping down while(motor[FrontLeft]!=0 || motor[FrontRight]!=0 || motor[BackLeft]!=0 || motor[BackRight]!=0) //if any motor is not at 0 { //forward section here if(motor[FrontLeft]>0&&directionLeft==1) //if the front left motor is greater than 0 { if(abs(motor[FrontLeft])<3) //first check to see if the difference is less than the step size { stepSize=abs(motor[FrontLeft]); //change the step size if it is } setLeft(getLeft()-stepSize); //then decrease both the left motors' power by the step size } if(motor[FrontRight]>0&&directionRight==1) //if the front right motor is greater than 0 { if(abs(motor[FrontRight])<3) //first check to see if the differece is less than the step size { stepSize=abs(motor[FrontRight]); //change the step size if it is } setRight(getRight()-stepSize); //then decrease both the right motors' power by the step size } //reverse section here if(motor[FrontLeft]<0&&directionLeft==-1) //if the front left motor is less than 0 { if(abs(motor[FrontLeft])<3) //first check to see if the difference is less than the step size { stepSize=abs(motor[FrontLeft]); //change the step size if it is } setLeft(getLeft()+stepSize); //then increase both the left motors' power by the step size } if(motor[FrontRight]<0&&directionRight==-1) //if the front right motor is greater than 0 { if(abs(motor[FrontRight])<3) //first check to see if the difference is less than the step size { stepSize=abs(motor[FrontRight]); //change the step size if it is } setRight(getRight()-stepSize); //then increase both right motors' power by the step size } wait1Msec(1); //wait, and repeat until all motors are stopped } }
bool Rect::Contains(const Point point) const { return ((point.X >= X) && (point.X <= getRight()) && (point.Y >= Y) && (point.Y <= getBottom())); }
AVLTreeNode<T*>* AVLTreeNode<T*>::getChild(char i) { return i<0 ? getLeft() : getRight(); }
void node::recount() // Пересчитывает вспомогательные величины, хранящиеся в вершине по детям { if (left != NULL) left->push(); if (right != NULL) right->push(); // Кол-во элементов в поддереве size = 1; if (getLeft() != NULL) size += getLeft()->getSize(); if (getRight() != NULL) size += getRight()->getSize(); // Сумма элементов в поддереве sum = value; if (getLeft() != NULL) sum += getLeft()->getSum(); if (getRight() != NULL) sum += getRight()->getSum(); // Минимум в поддереве min = value; int temp = min; // Потом сюда попробуем записать меньший из минимумов на поддеревьях if ( (getLeft() != NULL) || (getRight() != NULL) ) // Если хотябы в одном поддереве есть элементы { if (getLeft() != NULL) temp = getLeft()->getMin(); if (getRight() != NULL) if ( getRight()->getMin() < temp ) temp = getRight()->getMin(); } if (temp < min) min = temp; // Максимум в поддереве max = value; temp = max; // Потом сюда попробуем записать больший из максимумов на поддеревьях if ( (getLeft() != NULL) || (getRight() != NULL) ) // Если хотябы в одном поддереве есть элементы { if (getLeft() != NULL) temp = getLeft()->getMax(); if (getRight() != NULL) if ( getRight()->getMax() > temp ) temp = getRight()->getMax(); } if (temp > max) max = temp; // Тут определяется, убывает дерево или нет по потомкам isIncreasing = isDecreasing = false; if ( (getLeft() == NULL) && (getRight() == NULL) ) // Вариант, когда детей нет { isIncreasing = isDecreasing = true; return; } if ( (getLeft() != NULL) && (getRight() != NULL) ) // Вариант, когда оба ребенка есть { if ( getLeft()->getIsIncreas() && getRight()->getIsIncreas() && (value <= getRight()->getMin()) && (value >= getLeft()->getMax()) ) isIncreasing = true; if ( getLeft()->getIsDecreas() && getRight()->getIsDecreas() && (value <= getLeft()->getMin()) && (value >= getRight()->getMax()) ) isDecreasing = true; return; } if (getLeft() != NULL) // Вариант, когда нет левого, но есть правый { if ( getLeft()->getIsIncreas() && (value >= getLeft()->getMax()) ) isIncreasing = true; if ( getLeft()->getIsDecreas() && (value <= getLeft()->getMin()) ) isDecreasing = true; } else // Вариант, когда нет правого, но есть левый { if ( getRight()->getIsIncreas() && (value <= getRight()->getMin()) ) isIncreasing = true; if ( getRight()->getIsDecreas() && (value >= getRight()->getMax()) ) isDecreasing = true; } }
void FuzzyEngine::changeRight(int delta) { setRight(getRight() + delta); }
//---------------------------------------------------------- ofPoint ofRectangle::getTopRight() const { return ofPoint(getRight(),getTop()); }
void chaos::GameObject::drawGizmo(GLfloat scale){ renderer->drawDebugLine(getPosition(), getPosition()-scale*getFront(), glm::vec4(0,1,0,1)); renderer->drawDebugLine(getPosition(), getPosition()+scale*getRight(), glm::vec4(1,0,0,1)); renderer->drawDebugLine(getPosition(), getPosition()+scale*getUp(), glm::vec4(0,0,1,1)); }
bool ASTNode::isConstant() const { return getLeft()->isConstant() && getRight()->isConstant(); }
void Camera::moveRight( const GLfloat& amount ) { m_PosDelta += getRight() * amount; }
Matrix3x4f CameraUtility::getTransform() { Matrix3x4f transform(getRight(), getUp(), getBack(), getPosition()); return transform; }