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

Author Topic: Angle between 2 points  (Read 12093 times)

0 Members and 1 Guest are viewing this topic.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Angle between 2 points
« Reply #15 on: August 21, 2014, 06:14:24 pm »
If all you want to do is move something between two points you don't even need to calculate the angle. Something as simple as the following works.

sf::Vector2f norm = pt1 - pt2;
myObject.setPosition(pt1);

while (window.isOpen())
{
   myObject.move(norm * deltaTime);
}
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

electrux

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Angle between 2 points
« Reply #16 on: August 21, 2014, 06:39:09 pm »
huh?! it was that easy?! lol and i was even bothering my math teacher for a way >_<.. anyways thanks very much :D SFML rocks!!!! best library i seen to start with game programming (btw m new to game programming so sorry i dont know almost everything...) thanks again :D

electrux

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Angle between 2 points
« Reply #17 on: August 22, 2014, 07:21:55 am »
ok sorry but how did u define deltaTime? i tried Vector2f but it give me error that no function matches the operand *

electrux

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Angle between 2 points
« Reply #18 on: August 22, 2014, 07:40:53 am »
nevermind... got it working by multiplying by float thanks :D and again, SFML FTW!!!!

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Angle between 2 points
« Reply #19 on: August 22, 2014, 07:55:24 am »
ok sorry but how did u define deltaTime?

deltaTime is the frametime, which you should multiply with nearly every movement to prevent that your movements will be faster when you have more frames per seconds. Here is a great article about this topic



AlexAUT

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Angle between 2 points
« Reply #20 on: August 23, 2014, 09:06:34 pm »
If you don't want to reinvent the wheel, you could use Thor.Vectors that I have written. The module provides a lot of vector-related functionality, including the computation of angles in various situations.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: