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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Crembotz

Pages: [1]
1
General / Re: Is this good beginner code?
« on: July 20, 2019, 06:19:17 pm »
Why did you use extern on speed? Doesn't look like you're using it anywhere else...

2
General / Re: Calculating the gradient of a line
« on: July 17, 2019, 09:00:08 pm »
Also, I would highly encourage you to learn vector algebra. It's one of the most intuitive fields of math and can make a lot of geometric relations really simple to model.

In your example, instead of separate X and Y coordinates, you might have a position and direction vector, plus a scalar (float) for the speed.
sf::Vector2f position = ...;
sf::Vector2f direction = ...;
float speed = ...

The velocity would be the speed multiplied by the direction. The next position would simply be the current position, plus the velocity vector, scaled by the passed time:
sf::Vector2f velocity = speed * direction;
sf::Time passedTime = ...;

sf::Vector2f nextPosition = position + velocity * passedTime.asSeconds();

To get started, maybe look for an introductory course on vectors on the Internet. Regarding API, you can use SFML for the basic types and operations and my library Thor for advanced vector operations.

Thanks for the tip but I'm already quite familiar with vectors, it's just that the author's choice to go against a well-known formula really confused me, but I've got it figured it out thanks to you guys. The conclusions I reached regarding this section:
1. The numerator can be either the difference in the X-axis or the Y-axis, it doesn't matter as long you take care to multiply the variable that represents the object's velocity in that same axis by the gradient(in this case, since the difference in the X-axis in the numerator, then m_BulletDistanceX is multiplied by gradient).
Why is it so? Because the ratio between the velocity in both axes has to be gradient.
2. Which leads me to my second point, the variable ratioXY(bad name if you ask me, because it does NOT represent the ratio between the two axes) is quite pointless and can be exchanged by any other constant or discarded completely. From what I gather, it's here to further control the object's velocity in accordance with the distance it has to travel. Also dividing by (1+gradient) can be exchanged by any other action including gradient or it can be discarded completely if you're not interested in that "extra-control over the value" stuff.

And that's the weird way my brain works, hope this helps anyone and thank you guys so much for your help!!

3
General / Re: Calculating the gradient of a line
« on: July 16, 2019, 10:40:30 pm »
I don't suppose it matters which dimension you put first; it depends on which way it will be used. Who says which dimension is what :D
If y was first (y2-y1)/(x2-x1), I would presume that the gradient would be multiplied with m_BulletDistanceY instead.
I'm sorry, could you please explain what you mean by first?

4
General / Calculating the gradient of a line
« on: July 15, 2019, 10:34:21 pm »
Hi everyone.

I'm currently learning SFML by reading "Beginning C++ Game Programming" by John Horton. In chapter 9, we develop a top-down shooter. In pages 277 - 279, he describes the formula he used to calculate a gradient as (x2-x1)/(y2-y1), this is used then used in the following variable:
float ratioXY = m_BulletSpeed/(1+gradinet);// Calculate the ratio between x and y
which is then used to calculate how far the bullet will travel horizontally and vertically each frame:
m_BulletDistanceY = ratioXY;
 m_BulletDistanceX = ratioXY * gradient;
My question is, why did he calculate the inverse gradient? Why the regular formula, which is (y2-y1)/(x2-x1) causes the bullet to behave incorrectly(not moving towards its intended target, moves toward a different direction)?
Thank you very much for your time!

Pages: [1]
anything