void Draw::mouseMoveEvent( QMouseEvent *e ) { // printf("called mouse Move %d %d %d\n",_time.restart(), e->x(), e->y()); // draw if ((_tool==D_DRAW || _tool==D_OVERDRAW || _tool==D_PAINT) && _mousePressed && _currDPath) { Vec2f newLoc = unproject(e->x(), e->y(), _h); //printf("%f %f\n",newLoc.x(), newLoc.y()); if (_currDPath->getNumElements()==0 || _currDPath->distToLast2(newLoc) > 0) _currDPath->addVertex(newLoc.x(),newLoc.y(), mapPressure()); QPoint curs = _parent->mapFromGlobal(QCursor::pos()); if ((e->x() - curs.x())*(e->x() - curs.x()) + (e->y() - curs.y())*(e->y() - curs.y()) < 25) _parent->updateGL(); } else if (_tool == D_SELECT && _mousePressed && _selected) { Vec2f newLoc = unproject(e->x(), e->y(), _h); Vec2f delta(newLoc, _dragLoc); _selected->translate(delta); _dragLoc = newLoc; _dragDirty = true; _parent->updateGL(); } else if (_spliceIndex>0 && _selected && _tool==D_NUDGE) { // nudge Vec2f newLoc = unproject(e->x(), e->y(), _h); _selected->nudge(_spliceIndex, newLoc); } }
void City_layer::calculateRayByLocationInView(Ray* ray, const Vec2& location) { auto dir = Director::getInstance(); auto view = dir->getWinSize(); //auto mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); //auto mat=pCamera->getProjectionMatrix(); auto mat=pCamera->getViewProjectionMatrix(); Vec3 src = Vec3(location.x, location.y, -1); Vec3 nearPoint; unproject(mat, &view, &src, &nearPoint); src = Vec3(location.x, location.y, 1); Vec3 farPoint; unproject(mat, &view, &src, &farPoint); Vec3 direction; Vec3::subtract(farPoint, nearPoint, &direction); direction.normalize(); ray->_origin = nearPoint; ray->_direction = direction; }
void View3d::mouseMoveEvent(QMouseEvent* event) { int deltaX = event->globalX() - mMouse[0]; int deltaY = event->globalY() - mMouse[1]; if (event->buttons() == Qt::LeftButton) { mScene.setRotation( mScene.getRotation()[0] - M_PI / width() * deltaX, mScene.getRotation()[1] + M_PI / height() * deltaY, mScene.getRotation()[2]); } else if (event->buttons() == Qt::RightButton) { QPoint mouseLocal = mapFromGlobal(QPoint(mMouse[0], mMouse[1])); QPoint eventLocal = mapFromGlobal(QPoint(event->globalPos())); double distance = mCamera.getViewpointDistance(); std::vector<double> mouseUnprojected = unproject(mouseLocal, distance); std::vector<double> eventUnprojected = unproject(eventLocal, distance); mScene.setTranslation( mScene.getTranslation()[0] + (eventUnprojected[0] - mouseUnprojected[0]), mScene.getTranslation()[1] + (eventUnprojected[1] - mouseUnprojected[1]), mScene.getTranslation()[2] + (eventUnprojected[2] - mouseUnprojected[2])); } mMouse[0] = event->globalX(); mMouse[1] = event->globalY(); }
void EditTSCtrl::make3DMouseEvent(Gui3DMouseEvent & gui3DMouseEvent, const GuiEvent & event) { (GuiEvent&)(gui3DMouseEvent) = event; gui3DMouseEvent.mousePoint = event.mousePoint; if(!smCamOrtho) { // get the eye pos and the mouse vec from that... Point3F screenPoint((F32)gui3DMouseEvent.mousePoint.x, (F32)gui3DMouseEvent.mousePoint.y, 1.0f); Point3F wp; unproject(screenPoint, &wp); gui3DMouseEvent.pos = smCamPos; gui3DMouseEvent.vec = wp - smCamPos; gui3DMouseEvent.vec.normalizeSafe(); } else { // get the eye pos and the mouse vec from that... Point3F screenPoint((F32)gui3DMouseEvent.mousePoint.x, (F32)gui3DMouseEvent.mousePoint.y, 0.0f); Point3F np, fp; unproject(screenPoint, &np); gui3DMouseEvent.pos = np; smCamMatrix.getColumn( 1, &(gui3DMouseEvent.vec) ); } }
void drawLine3d(SDL_Surface *buf, struct vec4 a, struct vec4 b) { struct vec4 ua, ub; ua = unproject(a); ub = unproject(b); drawLine2d(buf, ua.x, ua.y, ub.x, ub.y); }
void ArcballCamera::roll(int prevX, int prevY, int currX, int currY) { if (prevX == currX && prevY == currY) return; prevY = (_pixelHeight - 1) - prevY; currY = (_pixelHeight - 1) - currY; Vec3f prev = unproject(prevX, prevY); Vec3f curr = unproject(currX, currY); const float kSphereRadius = 1; Ray3f prevRay(_pos, prev - _pos); Ray3f currRay(_pos, curr - _pos); Vec3f prevHit, currHit; bool didPrevHit = intersectRaySphere(prevRay, _target, kSphereRadius, prevHit); bool didCurrHit = intersectRaySphere(currRay, _target, kSphereRadius, currHit); if ( didPrevHit && didCurrHit ) { float c = dot(norm(currHit), norm(prevHit)); // Need to use the inverse rotation, since we're rotating the camera // rather than the scene. Quaternionf q = inverse(rotation( cross(prevHit - _target, currHit - _target), std::acos(c))); _pos = rotate(q, _pos - _target) + _target; } }
GeoBounds TaskProjection::unproject(const FlatBoundingBox& bb) const { assert(initialised); return GeoBounds (unproject(FlatGeoPoint(bb.bb_ll.Longitude, bb.bb_ur.Latitude)), unproject(FlatGeoPoint(bb.bb_ur.Longitude, bb.bb_ll.Latitude))); }
void add_frustum_vertices(int x, int y, const mat4 & inverse_mvp, const vec4 & viewport, btAlignedObjectArray<btVector3> & vertices) { vec2 win(x, y); vec3 p; p = unproject(vec3(win, 0.0f), inverse_mvp, viewport); vertices.push_back(convert_vec(p)); p = unproject(vec3(win, 1.0f), inverse_mvp, viewport); vertices.push_back(convert_vec(p)); }
Ray Camera::getRay(int x, int y) const { Vector near = unproject(Vector(x, y, 0)); Vector far = unproject(Vector(x, y, 10)); Vector diff = far - near; diff.normalize(); // fix for the fact that camera is actually positioned negativelly in space ;) diff.x *= -1; diff.z *= -1; return Ray(near, diff); }
QPointF screen_point_to_point_on_plane( QPointF pt, QRect viewport, Qt3DRender::QCamera *camera, float y ) { // get two points of the ray QVector3D l0 = unproject( QVector3D( pt.x(), viewport.height() - pt.y(), 0 ), camera->viewMatrix(), camera->projectionMatrix(), viewport ); QVector3D l1 = unproject( QVector3D( pt.x(), viewport.height() - pt.y(), 1 ), camera->viewMatrix(), camera->projectionMatrix(), viewport ); QVector3D p0( 0, y, 0 ); // a point on the plane QVector3D n( 0, 1, 0 ); // normal of the plane QVector3D l = l1 - l0; // vector in the direction of the line float d = QVector3D::dotProduct( p0 - l0, n ) / QVector3D::dotProduct( l, n ); QVector3D p = d * l + l0; return QPointF( p.x(), p.z() ); }
Vec2f Node2D::screenToObject( const Vec2f &pt ) const { // near plane intersection Vec3f p0 = unproject(pt.x, pt.y, 0.0f); // far plane intersection Vec3f p1 = unproject(pt.x, pt.y, 1.0f); // find (x, y) coordinates float t = (0.0f - p0.z) / (p1.z - p0.z); float x = (p0.x + t * (p1.x - p0.x)); float y = (p0.y + t * (p0.y - p1.y)); return Vec2f(p0.x, p0.y); }
/********************************************* ||myMouse() function ||Purpose: With the left mouse button you can start || and stop the snowflakes spinning. *********************************************/ void myMouse(int btn, int state, int x, int y) { iPOINT start, end; GLdouble *coord; if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { pDragMouseStart.x = x;//update mouse dragging start position pDragMouseStart.y = y;//update mouse dragging start position drawSecondSnowflake=1; //let it draw the second snowflake coord = unproject(x,y);//unproject the coordinates //Calculate position for coordinates w[2][0]=coord[0]; w[2][1]=coord[1]; w[1][0] = w[2][0] + ((1.037) * cos(5.23598776)); //find new x w[1][1] = w[2][1] + ((1.037) * sin(5.23598776)); //find new y w[0][0] = w[2][0] + ((1.037) * cos(4.1887902)); //find new x w[0][1] = w[2][1] + ((1.037) * sin(4.1887902)); //find new y //Refresh glutPostRedisplay(); } }
void motion(int x, int y) { vec2i mpos = unproject(x, y); if (mouse_action == MouseGoal && valid(mpos) && mpos != goal) { goal = mpos; changes |= GoalChanged; } else if (mouse_action == MouseInit && valid(mpos) && mpos != init) { init = mpos; vec2i diff = goal - init; initTheta = atan2(diff.y(), diff.x()); changes |= InitChanged; } else if (mouse_action == MouseTheta && valid(init)) { vec2i diff = mpos - init; initTheta = atan2(diff.y(), diff.x()); changes |= InitChanged; } if (changes) { searchResult = 0; } glutPostRedisplay(); }
Renderable *GraphicsManager::getWorldObjectAt(float x, float y) const { if (QueueMan.isQueueEmpty(kQueueVisibleWorldObject)) return 0; // Map the screen coordinates to OpenGL world screen coordinates y = _height - y; float x1, y1, z1, x2, y2, z2; if (!unproject(x, y, x1, y1, z1, x2, y2, z2)) return 0; Renderable *object = 0; QueueMan.lockQueue(kQueueVisibleWorldObject); const std::list<Queueable *> &objects = QueueMan.getQueue(kQueueVisibleWorldObject); for (std::list<Queueable *>::const_iterator o = objects.begin(); o != objects.end(); ++o) { Renderable &r = static_cast<Renderable &>(**o); if (!r.isClickable()) // Object isn't clickable, don't check continue; // If the line intersects with the object, return it if (r.isIn(x1, y1, z1, x2, y2, z2)) { object = &r; break; } } QueueMan.unlockQueue(kQueueVisibleWorldObject); return object; }
IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::unproject( const Eigen::PlainObjectBase<Derivedwin> & win) { Eigen::PlainObjectBase<Derivedwin> obj; unproject(win,obj); return obj; }
void overview_click(Overview * self, float sx, float sy, int clicked, int released) { float x, y; sx -= self->zoomx; sy -= self->zoomy; float zoom = game->viewport->zoom * pow(2, self->zoom / 10.0); sx /= zoom; sy /= zoom; unproject(game->viewport, sx, sy, 0, & x, & y); int ix = floor(x / 128 + 3.5); int iy = floor(y / 128 + 3.5); if (ix >= 0 && iy >= 0 && ix < 7 && iy < 7) { self->selected = 1 + ix + iy * 7; self->mx = sx; self->my = sy; if (clicked) { game->swap_level = self->selected; } #line 161 else if (released) { overview_swap_levels(self, self->selected, game->swap_level); } } #line 163 if (released) { game->swap_level = 0; } }
QPointF GLScene::mapToScene(const QPointF &p){ // Code below will work OK while projection is ortogonal // For some reason in perspective projection everything is flipped and not accurate QVector4D rNear = unproject(QVector3D(p.x(), p.y(), -1)); QVector4D rFar = unproject(QVector3D(p.x(), p.y(), 1)); QVector<QVector3D> triangle; triangle << QVector3D(0, 0, 0) << QVector3D(0, 1, 0) << QVector3D(1, 0, 0); QVector3D normal = QVector3D::normal(triangle.at(0), triangle.at(1), triangle.at(2)); qreal d1 = QVector3D::dotProduct(rNear.toVector3D() - triangle.at(0), normal); qreal d2 = QVector3D::dotProduct(rFar.toVector3D() - triangle.at(0), normal); QVector3D point = rNear.toVector3D() + (rFar.toVector3D() - rNear.toVector3D()) * (-d2 / (d2 - d1)); return point.toPointF(); }
void ModuleDescriptor::removeSubscription_message(uint8_t hostID, uint16_t spaceID, uint16_t MCID) { (*projections[hostID][spaceID])->removeSubscription(DC, MCID); if (!(*projections[hostID][spaceID])->subscriptionCount[DC] && !(*projections[hostID][spaceID])->subscriptionCount[ST]) { unproject(hostID, spaceID); } }
void ModuleDescriptor::removeSubscription_stream(uint8_t hostID, uint16_t spaceID, uint16_t SID) { (*projections[hostID][spaceID])->removeSubscription(ST, SID); if (!(*projections[hostID][spaceID])->subscriptionCount[DC] && !(*projections[hostID][spaceID])->subscriptionCount[ST]) { unproject(hostID, spaceID); } }
bool TaskProjection::update_fast() { assert(initialised); GeoPoint old_loc = location_mid; location_mid.Longitude = location_max.Longitude.Fraction(location_min.Longitude, fixed_half); location_mid.Latitude = location_max.Latitude.Fraction(location_min.Latitude, fixed_half); cos_midloc = location_mid.Latitude.fastcosine() * fixed_scale; r_cos_midloc = fixed_one/cos_midloc; approx_scale = unproject(FlatGeoPoint(0,-1)).distance(unproject(FlatGeoPoint(0,1))) / 2; return !(old_loc == location_mid); }
void Camera::pickRay(const Viewport* viewport, float x, float y, Ray* dst) { // Get the world-space position at the near clip plane. Vector3 nearPoint; unproject(viewport, x, y, 0.0f, &nearPoint); // Get the world-space position at the far clip plane. Vector3 farPoint; unproject(viewport, x, y, 1.0f, &farPoint); // Set the direction of the ray. Vector3 direction; Vector3::subtract(farPoint, nearPoint, &direction); direction.normalize(); dst->set(nearPoint, direction); }
boost::optional<Eigen::Vector3f> read_depth_and_unproject(const Vector2i &screen_pos, const Eigen::Matrix4f &model, const Eigen::Matrix4f &proj, const Vector2i &viewportSize, bool flipY) { float z = read_depth(screen_pos, flipY, viewportSize.y()); if (z == 1.0f) return boost::none; return unproject(Eigen::Vector3f{(float)screen_pos.x(), (float)screen_pos.y(), z}, model, proj, viewportSize, flipY); }
void C3DCamera::getAxes(const C3DViewport* viewport, float x, float y, C3DRay* dst) { // Get the world-space position at the near clip plane. Vector3 nearPoint; Vector3 src = Vector3 (x,y,0.0f); unproject(viewport, &src, &nearPoint); // Get the world-space position at the far clip plane. Vector3 farPoint; src = Vector3 (x,y,1.0f); unproject(viewport, &src, &farPoint); // Set the direction of the ray. Vector3 direction; Vector3::subtract(farPoint, nearPoint, &direction); direction.normalize(); dst->set(nearPoint, direction); }
void ModuleDescriptor::removeSubscriptions_stream(uint8_t hostID, uint16_t spaceID) { for (uint16_t i = 0; i < NodeEntry::Main[ST].count(); i++) { removeSubscription_stream(hostID, spaceID, i); } if (!(*projections[hostID][spaceID])->subscriptionCount[DC]) { unproject(hostID, spaceID); } }
void ArcballCamera::move(int prevX, int prevY, int currX, int currY) { if (prevX == currX && prevY == currY) return; // The viewer gives us y coordinates which increase downwards. We want ones // which increase upwards, so we need to invert them. prevY = (_pixelHeight - 1) - prevY; currY = (_pixelHeight - 1) - currY; Vec3f prev = unproject(prevX, prevY, 0.6); Vec3f curr = unproject(currX, currY, 0.6); Vec3f delta = curr - prev; // Because we're moving the camera not the scene, we need to do the // opposite movement. _pos = (_pos - delta); _target = (_target - delta); }
Point GameTerrain::from_screen_point(GraphicContext &gc, const Point &screen_point, const Mat4f &projection, const Mat4f &modelview2, const Rect &viewport) { OpenGL::set_active(gc); float depth; glReadPixels(screen_point.x, screen_point.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth); Mat4f modelview = modelview2; modelview = modelview * Mat4f::translate(-size.width*2.0f, 0.0f, -size.height*2.0f); Vec3f pos = unproject(Vec3f((float)screen_point.x, (float)screen_point.y, depth), modelview, projection, viewport); return Point((int)(pos.x+0.5f),(int)(pos.z+0.5f)); }
static int motion_cb(Ihandle *ih,int x,int y,char* status) { (void)status; if (move) { double dif_x, dif_y; double dx, dy, dz; double x1, y1, z1; double x2, y2, z2; double angle, norma; int height = IupGetInt2(ih, "RASTERSIZE"); IupGLMakeCurrent(ih); dif_x = x - pos_x; dif_y = y - pos_y; pos_x = x; pos_y = y; angle = sqrt(dif_x*dif_x + dif_y*dif_y); unproject (pos_x, INVERT_Y(pos_y), &x1, &y1, &z1); unproject ((double)(dif_y+pos_x), (double)(dif_x+INVERT_Y(pos_y)), &x2, &y2, &z2); dx = x2-x1; dy = y2-y1; dz = z2-z1; norma = sqrt(dx*dx + dy*dy + dz*dz); dx /= norma; dy /= norma; dz /= norma; glTranslated(0.5, 0.5, 0.5); glRotated (angle, dx, dy, dz); glTranslated(-0.5, -0.5, -0.5); draw_cube(); glFlush(); IupGLSwapBuffers(ih); } return IUP_DEFAULT; }
void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, const Vec2& location) { auto dir = Director::getInstance(); auto view = dir->getWinSize(); Mat4 mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); Vec3 src = Vec3(location.x, location.y, -1); Vec3 nearPoint; unproject(mat, &view, &src, &nearPoint); src = Vec3(location.x, location.y, 1); Vec3 farPoint; unproject(mat, &view, &src, &farPoint); Vec3 direction; Vec3::subtract(farPoint, nearPoint, &direction); direction.normalize(); ray->_origin = nearPoint; ray->_direction = direction; }
IGL_INLINE int igl::unproject( const Eigen::PlainObjectBase<Derivedwin> & win, Eigen::PlainObjectBase<Derivedobj> & obj) { Eigen::Vector3d dwin(win(0),win(1),win(2)); Eigen::Vector3d dobj; int ret = unproject(dwin(0),dwin(1),dwin(2), &dobj.data()[0], &dobj.data()[1], &dobj.data()[2]); obj(0) = dobj(0); obj(1) = dobj(1); obj(2) = dobj(2); return ret; }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void Graph::draw(QPainter &p) { QPolygonF poly; unproject(poly); p.setRenderHint(QPainter::Antialiasing, antiAliasing()); if ( dropShadow() ) { p.translate(2,2); p.setPen(QPen(QColor(128,128,128,128), lineWidth())); p.drawPolyline(poly); p.translate(-2,-2); } p.setPen(pen()); p.drawPolyline(poly); }