Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Shape position problem  (Read 4437 times)

0 Members and 2 Guests are viewing this topic.

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Shape position problem
« on: October 06, 2008, 08:34:19 pm »
hi!

when i using shapes a get a wierd problem. when i want to look up where they are, GetPosition().x and .y is allways 0.
Right now I am using circles and this i my code:
Code: [Select]
float Plupp::Distance(Plupp *Other){
sf::Vector2<float> ThisCords = this->Shape.GetPosition();

float Dist = sqrt(pow((this->Shape.GetPosition().x - Other->GetShape().GetPosition().x),2)
+ pow((this->Shape.GetPosition().y - Other->GetShape().GetPosition().y),2));

std::cout << ThisCords.x << std::endl;
std::cout << ThisCords.y << std::endl;

return Dist;
}

This is my code to massure the distance between 2 "plupps". The both plupps thinks they is standing on top on eachother even if they is half a screen apart! my output from this is 2 zeroes. I have been having this problem before and i belive I gave up that time.
thanks in advance for any help!

edit: ops, maybe this could be in graphics :oops:
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Shape position problem
« Reply #1 on: October 06, 2008, 08:43:38 pm »
The position of the shape and the position of its points are completely separate. If create a circle centered on (x, y) its position will still be (0, 0).

If you want to get the position at the center of the shape, create it around the origin and move it with the usual Drawable's functions (Move, SetPosition, ...).
Laurent Gomila - SFML developer

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Shape position problem
« Reply #2 on: October 06, 2008, 08:59:03 pm »
So the GetPosition is only relative to the shape itself?
Sorry but i dont really follow you, is'nt it any function that return the shapes position in the renderwindow?

 :oops:
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Shape position problem
« Reply #3 on: October 07, 2008, 07:42:14 am »
Quote
So the GetPosition is only relative to the shape itself?

It's rather the points' position that are relative to the shape's one. So if the center of your circle is (100, 200), it will be offseted by (100, 200) from the shape's position (which is the origin by default).
Laurent Gomila - SFML developer

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Shape position problem
« Reply #4 on: May 27, 2009, 09:19:21 pm »
hi, havn't been using sfml for a while now and started some days ago and I stumbled on the same problem, kinda.

i want a sprite to follow the mousepointer using the following code:

Quote
sf::Vector2<int> Temp = GridCord(App);
hoverBlock->GetSprite().SetPosition(Temp.x, Temp.y);


where GridCord(App) returns a position on screen relative to the mouse (which is tested and correct). but the sprite doesn'nt move:(

why?
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Shape position problem
« Reply #5 on: May 27, 2009, 10:09:39 pm »
Maybe GetSprite() returns a copy instead of a reference to the actual sprite?
Laurent Gomila - SFML developer

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Shape position problem
« Reply #6 on: May 28, 2009, 02:22:50 pm »
Ahhh, thank you so much! of cause it is!:)
Why can't things just work?

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: Shape position problem
« Reply #7 on: November 12, 2012, 02:08:41 pm »
So I am back again after a few years with the same problem=/

I want to drawa bunch of dots connected by lines.
First the dots:
   m_shape = Shape::Circle(pos, 5, Color(255, 100, 100));
   m_shape.SetPosition(pos);

Then the lines:
   Vector2f n1Pos = n1->GetPos();
   Vector2f n2Pos = n2->GetPos();

   m_shape = Shape::Line(n1Pos, n2Pos, 3, Color(200, 200, 200));
where n1 and n2 are two list iterators to dots and GetPos is defined as
return m_shape.GetPosition();

These are drawn like this:
   //drawall edges
   for(list<Edge>::iterator it = m_edges.begin(); it != m_edges.end(); it++)
   {
      m_app.Draw(it->GetShape());
   }

   //draw all Nodes
   for(list<Node>::iterator it = m_nodes.begin(); it != m_nodes.end(); it++)
   {
      m_app.Draw(it->GetShape());
   }

The problem is that all the lines are showing up fine but the dotsare not showing.
 If i remove the
   m_shape.SetPosition(pos);
from the dot constructor, it's the opposite :o
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shape position problem
« Reply #8 on: November 12, 2012, 02:31:11 pm »
Could you please show a complete and minimal example that reproduces the problem?

And... don't you want to switch to SFML 2?
Laurent Gomila - SFML developer

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: Shape position problem
« Reply #9 on: November 13, 2012, 07:56:59 am »
So i tried to change to 2.0 and made it compile but the linking doesnt work to good for me.
Got the
"The application failed to initialize properly (0xc0150002). Click on OK to terminate the application."-error I heared some other people been having on vs 2010, is it the same on vs 2005? Do I need to compile sfml myself? I have tried both with static and dynamic.

sorry for making this thread into some general help-regen-out-thread:(
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shape position problem
« Reply #10 on: November 13, 2012, 04:12:31 pm »
Quote
Do I need to compile sfml myself?
If you use VS2005, yes.
Laurent Gomila - SFML developer