Exemplo n.º 1
0
void RenderManager::RenderObjectAt(Shape* shape, const a2de::Vector2D& screen_position) {
    if(shape == nullptr) return;
    a2de::Vector2D old_pos(shape->GetPosition());
    shape->SetPosition(screen_position);
    shape->Draw(al_get_backbuffer(_display_context));
    shape->SetPosition(old_pos);
}
Exemplo n.º 2
0
void RenderManager::RenderObjectAt(IBoundingBox* bounding_box, const a2de::Vector2D& screen_position) {
    if(bounding_box == nullptr) return;
    a2de::Vector2D old_pos(bounding_box->GetTransform().GetPosition());
    bounding_box->GetTransform().SetPosition(screen_position);
    bounding_box->Draw(al_get_backbuffer(_display_context));
    bounding_box->GetTransform().SetPosition(old_pos);
}
Exemplo n.º 3
0
void RenderManager::RenderObjectAt(Object* object, const a2de::Vector2D& screen_position) {
    if(object == nullptr) return;
    a2de::Vector2D old_pos(object->GetBody()->GetPosition());
    object->GetBody()->SetPosition(screen_position);
    object->Draw(al_get_backbuffer(_display_context));
    object->GetBody()->SetPosition(old_pos);
}
Exemplo n.º 4
0
void noFigure::HandleEvent(const unsigned int id)
{
    // Bei ID = 0 ists ein Laufevent, bei allen anderen an abgeleitete Klassen weiterleiten
    if(id)
    {
        HandleDerivedEvent(id);
    }
    else
    {
        current_ev = NULL;
        WalkFigure();

        // Alte Richtung und Position für die Berechnung der Sichtbarkeiten merken
        unsigned char old_dir = GetCurMoveDir();

        MapPoint old_pos(pos);

        switch(fs)
        {
            case FS_GOHOME:
            case FS_GOTOGOAL:
            {
                WalkToGoal();
            } break;

            case FS_JOB:
            {
                Walked();
                break;
            }
            case FS_WANDER:
            {
                Wander();
                break;
            }
        }

        // Ggf. Sichtbereich testen
        if(GetVisualRange())
        {

            // Use old position (don't use this->x/y because it might be different now
            // Figure could be in a ship etc.)
            gwg->RecalcMovingVisibilities(old_pos, player, GetVisualRange(), old_dir, NULL);


            std::vector<noBase*> figures = gwg->GetDynamicObjectsFrom(old_pos);

            // Wenn Figur verschwunden ist, muss ihr ehemaliger gesamter Sichtbereich noch einmal
            // neue berechnet werden
            if(!helpers::contains(figures, this))
                CalcVisibilities(old_pos);
        }

    }
}
Exemplo n.º 5
0
void MainGraphicsView::mouseMove(int m_x, int m_y) {
    if( this->single_left_mouse_down ) {
        // only if the left mouse is down, and this isn't a multitouch event (otherwise single_left_mouse_down should be set to false)
        //qDebug("    lmb");
        if( this->has_last_mouse ) {
            //qDebug("    has last mouse");
            /*QPointF old_pos = this->mapToScene(this->last_mouse_x, this->last_mouse_y);
            QPointF new_pos = this->mapToScene(event->x(), event->y());*/
            //qDebug("%d, %d -> %d, %d", last_mouse_x, last_mouse_y, m_x, m_y);
            QPointF old_pos(this->last_mouse_x, this->last_mouse_y);
            QPointF new_pos(m_x, m_y);
            QPointF diff = old_pos - new_pos; // n.b., scene scrolls in opposite direction to mouse movement

            // drag - we do this ourselves rather than using drag mode QGraphicsView::ScrollHandDrag, to avoid conflict with multitouch
            QPointF centre = this->getCenter();
            QPoint centre_pixels = this->mapFromScene(centre);
            centre_pixels.setX( centre_pixels.x() + diff.x() );
            centre_pixels.setY( centre_pixels.y() + diff.y() );
            centre = this->mapToScene(centre_pixels);
            //this->centerOn(centre);
            // have problems on Android with Qt 5.3 if we try to call centerOn() directly from an event callback (the screen doesn't update during the touch operation)
            this->has_new_center_on = true;
            this->new_center_on = centre;
            //qDebug("        post centre on: %f, %f", new_center_on.x(), new_center_on.y());

            // need to check against drag_tol_c, otherwise simply clicking can cause us to move with kinetic motion (at least on Android)
            if( fabs(diff.x()) > drag_tol_c || fabs(diff.y()) > drag_tol_c ) {
                int time_ms = game_g->getElapsedMS() - last_mouse_ms; // we don't use getElapsedFrameMS(), as we don't know how many times mouseMove() may have been called per frame
                if( time_ms > 0 ) {
                    diff /= (float)time_ms;
                    this->has_kinetic_scroll = true;
                    this->kinetic_scroll_dir.set(diff.x(), diff.y());
                    this->kinetic_scroll_speed = this->kinetic_scroll_dir.magnitude();
                    this->kinetic_scroll_dir /= this->kinetic_scroll_speed;
                    this->kinetic_scroll_speed = std::min(this->kinetic_scroll_speed, 1.0f);
                    //qDebug("    speed: %f", this->kinetic_scroll_speed);
                }
            }
            else {
                this->has_kinetic_scroll = false;
            }
            //qDebug("    has last mouse done");
        }
        else {
            this->has_kinetic_scroll = false;
        }
        this->has_last_mouse = true;
        this->last_mouse_x = m_x;
        this->last_mouse_y = m_y;
        this->last_mouse_ms = game_g->getElapsedMS();
    }
}
Exemplo n.º 6
0
int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "Fading Dots");
    window.setFramerateLimit(60);

    sf::Vector2f old_pos(0.f, 0.f);
    const int STEP = 1;

    std::list<sf::CircleShape> points;

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();
        }

        // Check if the mouse has moved
        sf::Vector2f pos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));
        if(pos != old_pos)
        {
            // Create and add a new circle to the points list.
            sf::CircleShape cs;
            cs.setRadius(10.f);
            cs.setPosition(pos);
            cs.setFillColor(sf::Color::Red);
            points.push_back(cs);

            old_pos = pos;
        }

        window.clear();

        for(auto it = points.begin(); it != points.end(); ++it)
        {
            window.draw(*it);
            if(it->getFillColor().a-STEP < 0) // When the transparency falls below zero (= invisible) then erase the dot.
                it = points.erase(it);
            else // Otherwise draw it with a increasing green touch (turns yellowish).
                it->setFillColor(sf::Color(255, it->getFillColor().g+STEP, 0, it->getFillColor().a-STEP));
        }

        window.display();
    }
}
Exemplo n.º 7
0
bool AutoFile::open(FILE *_f, bool takeOwnership)
{
  if ( f )
    close();

  filesize = max_size;
  f = _f;

  if ( f )
  {
    fsize_t old_pos(pos());

    if ( portable_seek(f, 0, SEEK_END) == 0 )
      filesize = portable_tell(f);

    portable_seek(f, old_pos, SEEK_SET);
    own_file = takeOwnership;
  }

  return isOpen();
}
Exemplo n.º 8
0
// Returns "distance" between target destination and resulting xfrom
F32 LLDrawable::updateXform(BOOL undamped)
{
	BOOL damped = !undamped;

	// Position
	LLVector3 old_pos(mXform.getPosition());
	LLVector3 target_pos;
	if (mXform.isRoot())
	{
		// get root position in your agent's region
		target_pos = mVObjp->getPositionAgent();
	}
	else
	{
		// parent-relative position
		target_pos = mVObjp->getPosition();
	}
	
	// Rotation
	LLQuaternion old_rot(mXform.getRotation());
	LLQuaternion target_rot = mVObjp->getRotation();
	//scaling
	LLVector3 target_scale = mVObjp->getScale();
	LLVector3 old_scale = mCurrentScale;
	LLVector3 dest_scale = target_scale;
	
	// Damping
	F32 dist_squared = 0.f;
	F32 camdist2 = (mDistanceWRTCamera * mDistanceWRTCamera);

	if (damped && isVisible())
	{
		F32 lerp_amt = llclamp(LLCriticalDamp::getInterpolant(OBJECT_DAMPING_TIME_CONSTANT), 0.f, 1.f);
		LLVector3 new_pos = lerp(old_pos, target_pos, lerp_amt);
		dist_squared = dist_vec_squared(new_pos, target_pos);

		LLQuaternion new_rot = nlerp(lerp_amt, old_rot, target_rot);
		dist_squared += (1.f - dot(new_rot, target_rot)) * 10.f;

		LLVector3 new_scale = lerp(old_scale, target_scale, lerp_amt);
		dist_squared += dist_vec_squared(new_scale, target_scale);

		if ((dist_squared >= MIN_INTERPOLATE_DISTANCE_SQUARED * camdist2) &&
			(dist_squared <= MAX_INTERPOLATE_DISTANCE_SQUARED))
		{
			// interpolate
			target_pos = new_pos;
			target_rot = new_rot;
			target_scale = new_scale;
		}
		else
		{
			// snap to final position
			dist_squared = 0.0f;
			if (getVOVolume() && !isRoot())
			{ //child prim snapping to some position, needs a rebuild
				gPipeline.markRebuild(this, LLDrawable::REBUILD_POSITION, TRUE);
			}
		}
	}

	if ((mCurrentScale != target_scale) ||
		(!isRoot() && 
		 (dist_squared >= MIN_INTERPOLATE_DISTANCE_SQUARED || 
		 !mVObjp->getAngularVelocity().isExactlyZero() ||
		 target_pos != mXform.getPosition() ||
		 target_rot != mXform.getRotation())))
	{ //child prim moving or scale change requires immediate rebuild
		gPipeline.markRebuild(this, LLDrawable::REBUILD_POSITION, TRUE);
	}
	else if (!getVOVolume() && !isAvatar())
	{
		movePartition();
	}

	// Update
	mXform.setPosition(target_pos);
	mXform.setRotation(target_rot);
	mXform.setScale(LLVector3(1,1,1)); //no scale in drawable transforms (IT'S A RULE!)
	mXform.updateMatrix();
	
	mCurrentScale = target_scale;
	
	if (mSpatialBridge)
	{
		gPipeline.markMoved(mSpatialBridge, FALSE);
	}
	return dist_squared;
}
void TrackDisplay::update(float wall_dt, float ros_dt) {
	V_TrackMsg local_queue;

	{
		boost::mutex::scoped_lock lock(queue_mutex_);

		local_queue.swap(message_queue_);
	}

	for (size_t t = 0; t < local_queue.size(); t++) {
		const articulation_msgs::TrackMsg::ConstPtr& track_message =
				local_queue[t];

		for(size_t l=0;l<lines[track_message->id].size();l++)
			lines[track_message->id][l]->clear();
		recycleLines.insert(recycleLines.begin(),
				lines[track_message->id].begin(),
				lines[track_message->id].end());

		lines[track_message->id].clear();
	}

	for (size_t t = 0; t < local_queue.size(); t++) {
		const articulation_msgs::TrackMsg::ConstPtr& track_message =
				local_queue[t];

		btTransform framePose;
		btVector3 lineScale(lineWidth_, lineWidth_, lineWidth_);
		transform(track_message, framePose);

		int channel_w = -1;
		int channel_h = -1;
		for (size_t i = 0; i < track_message->channels.size(); i++) {
			if (track_message->channels[i].name == "width")
				channel_w = (int) i;
			if (track_message->channels[i].name == "height")
				channel_h = (int) i;
		}

		Ogre::Vector3 old_pos(0,0,0);
		for (size_t i = 0; i < track_message->pose.size(); i++) {
			const geometry_msgs::Pose& geo_pose = track_message->pose[i];

			btTransform rectangle_pose(btQuaternion(geo_pose.orientation.x,
					geo_pose.orientation.y, geo_pose.orientation.z,
					geo_pose.orientation.w), btVector3(geo_pose.position.x,
					geo_pose.position.y, geo_pose.position.z));

			Ogre::Vector3 pos, scale;
			Ogre::Quaternion orient;
			transform(framePose * rectangle_pose, lineScale, pos, orient, scale);

			btVector3 color(color_.r_, color_.g_, color_.b_);	// fixed color

			double f =track_message->id / 7.0;
			color = modifyColor( color,  trackColor_, f - floor(f) );
			color = modifyColor( color,  poseColor_, i / (double)track_message->pose.size() );

			if(displayStyle_ == ds_line) {
				if(i==0) old_pos = pos;
				createLine(pos, old_pos, scale,
						color,
						lines[track_message->id],false);
				old_pos = pos;
			} else
			if(displayStyle_ == ds_cross_line) {
				if(i==0) old_pos = pos;
				createLine(pos, old_pos, scale,
						color,
						lines[track_message->id],true);
				old_pos = pos;
			} else
			if(displayStyle_ == ds_axes) {
				createAxes(pos, orient, scale,
						color,
						lines[track_message->id]);
			} else
			if(displayStyle_ == ds_rectangle) {
				createRectangle(pos, orient, scale,
						channel_w==-1? lineWidth_*5 : track_message->channels[channel_w].values[i],
						channel_h==-1? lineWidth_*5 : track_message->channels[channel_h].values[i],
						color,
						lines[track_message->id]);
			}
		}
	}
}
Exemplo n.º 10
0
// Returns "distance" between target destination and resulting xfrom
F32 LLDrawable::updateXform(BOOL undamped)
{
	BOOL damped = !undamped;

	// Position
	LLVector3 old_pos(mXform.getPosition());
	LLVector3 target_pos;
	if (mXform.isRoot())
	{
		// get root position in your agent's region
		target_pos = mVObjp->getPositionAgent();
	}
	else
	{
		// parent-relative position
		target_pos = mVObjp->getPosition();
	}
	
	// Rotation
	LLQuaternion old_rot(mXform.getRotation());
	LLQuaternion target_rot = mVObjp->getRotation();
	//scaling
	LLVector3 target_scale = mVObjp->getScale();
	LLVector3 old_scale = mCurrentScale;
	
	// Damping
	F32 dist_squared = 0.f;
	F32 camdist2 = (mDistanceWRTCamera * mDistanceWRTCamera);

	if (damped && isVisible())
	{
		F32 lerp_amt = llclamp(LLCriticalDamp::getInterpolant(OBJECT_DAMPING_TIME_CONSTANT), 0.f, 1.f);
		LLVector3 new_pos = lerp(old_pos, target_pos, lerp_amt);
		dist_squared = dist_vec_squared(new_pos, target_pos);

		LLQuaternion new_rot = nlerp(lerp_amt, old_rot, target_rot);
		// FIXME: This can be negative! It is be possible for some rots to 'cancel out' pos or size changes.
		dist_squared += (1.f - dot(new_rot, target_rot)) * 10.f;

		LLVector3 new_scale = lerp(old_scale, target_scale, lerp_amt);
		dist_squared += dist_vec_squared(new_scale, target_scale);

		if ((dist_squared >= MIN_INTERPOLATE_DISTANCE_SQUARED * camdist2) &&
			(dist_squared <= MAX_INTERPOLATE_DISTANCE_SQUARED))
		{
			// interpolate
			target_pos = new_pos;
			target_rot = new_rot;
			target_scale = new_scale;
		}
		else if (mVObjp->getAngularVelocity().isExactlyZero())
		{
			// snap to final position (only if no target omega is applied)
			dist_squared = 0.0f;
			if (getVOVolume() && !isRoot())
			{ //child prim snapping to some position, needs a rebuild
				gPipeline.markRebuild(this, LLDrawable::REBUILD_POSITION, TRUE);
			}
		}
	}
	else
	{
		// The following fixes MAINT-1742 but breaks vehicles similar to MAINT-2275
		// dist_squared = dist_vec_squared(old_pos, target_pos);

		// The following fixes MAINT-2247 but causes MAINT-2275
		//dist_squared += (1.f - dot(old_rot, target_rot)) * 10.f;
		//dist_squared += dist_vec_squared(old_scale, target_scale);
	}

	LLVector3 vec = mCurrentScale-target_scale;
	
	if (vec*vec > MIN_INTERPOLATE_DISTANCE_SQUARED)
	{ //scale change requires immediate rebuild
		mCurrentScale = target_scale;
		gPipeline.markRebuild(this, LLDrawable::REBUILD_POSITION, TRUE);
	}
	else if (!isRoot() && 
		 (!mVObjp->getAngularVelocity().isExactlyZero() ||
			dist_squared > 0.f))
	{ //child prim moving relative to parent, tag as needing to be rendered atomically and rebuild
		dist_squared = 1.f; //keep this object on the move list
		if (!isState(LLDrawable::ANIMATED_CHILD))
		{			
			setState(LLDrawable::ANIMATED_CHILD);
			gPipeline.markRebuild(this, LLDrawable::REBUILD_ALL, TRUE);
			mVObjp->dirtySpatialGroup();
		}
	}
	else if (!isRoot() &&
			((dist_vec_squared(old_pos, target_pos) > 0.f)
			|| (1.f - dot(old_rot, target_rot)) > 0.f))
	{ //fix for BUG-840, MAINT-2275, MAINT-1742, MAINT-2247
		gPipeline.markRebuild(this, LLDrawable::REBUILD_POSITION, TRUE);
	}
	else if (!getVOVolume() && !isAvatar())
	{
		movePartition();
	}

	// Update
	mXform.setPosition(target_pos);
	mXform.setRotation(target_rot);
	mXform.setScale(LLVector3(1,1,1)); //no scale in drawable transforms (IT'S A RULE!)
	mXform.updateMatrix();

	if (mSpatialBridge)
	{
		gPipeline.markMoved(mSpatialBridge, FALSE);
	}
	return dist_squared;
}
Exemplo n.º 11
0
void RenderManager::RenderObjectAt(Shape& shape, const a2de::Vector2D& screen_position, bool filled) {
    a2de::Vector2D old_pos(shape.GetPosition());
    shape.SetPosition(screen_position);
    RenderObject(shape, filled);
    shape.SetPosition(old_pos);
}
Exemplo n.º 12
0
//void RenderManager::RenderObjectAt(Entity* object, const a2de::Vector2D& screen_position) {
//    if(object == nullptr) return;
//    a2de::Vector2D old_pos(object->GetBody()->GetPosition());
//    object->GetBody()->SetPosition(screen_position);
//    object->Render(al_get_backbuffer(_display_context));
//    object->GetBody()->SetPosition(old_pos);
//}
//
void RenderManager::RenderObjectAt(Sprite& sprite, const a2de::Vector2D& screen_position) {
    a2de::Vector2D old_pos(sprite.GetPosition());
    sprite.SetPosition(screen_position);
    sprite.Draw(al_get_backbuffer(_display_context));
    sprite.SetPosition(old_pos);
}