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 - SkeleDotCpp

Pages: [1]
1
General / Re: What Is Wrong With This Line Algorithm?
« on: May 18, 2019, 02:15:08 am »
Oh wow, it worked. I don't know how that passed my potato brain, but thank you for responding!

2
General / [SOLVED] What Is Wrong With This Line Algorithm?
« on: May 17, 2019, 02:43:02 am »
I am trying to make a function that draws a line from a point to another.
Here is what I have:
const double PI = 3.14159265;

//Line shape
void line(sf::RenderWindow &win, int ax, int ay, int bx, int by) {
        //Angle
        int xDist = bx - ax;
        int yDist = by - ay;
        int length = sqrt((xDist * xDist) + (yDist * yDist)); //c = sqrt(a^2 + b^2)
        float angle = atan2(yDist, xDist) * 180 / PI; //Get angle and convert into degrees

        //Draw a rectangle as the line
        sf::RectangleShape line;
        line.setSize(sf::Vector2f(length, 3));
        line.setOrigin(0, line.getSize().y / 2); //Set the origin of the rectangle at left-middle
        line.setRotation(angle); //Rotate the rectangle by the angle calculated

        //Draw the rectangle
        win.draw(line);
}

And when I call it like so, it works perfectly fine:
line(window, 0, 0, mouseX, mouseY);

Note: mouseX, and mouseY are both defined prior.

But the problem is that when I call it like so, I get the line flipped by 180 degrees:
line(window, mouseX, mouseY, 0, 0);

And if I set the rotation by the angle + 180, it works fine, until I go back to the first method of calling it
(0,0, mouseX, mouseY)

Which now produces the line flipped by 180 degrees.

What exactly is the problem with the algorithm?

3
Audio / Re: OpenAL32 Credits
« on: October 08, 2018, 05:16:56 am »
Thank you for the links, but can you explain to me a bit more of what I exactly need to do?
Do I need to include that whole license with the game as a README.txt, or do I put them as text in the game. When the user clicks on the credits button?

And also, this link does not open for me for some reason
http://kcat.strangesoft.net/openal.html

It gives me this error:
kcat.strangesoft.net didn’t send any data.
ERR_EMPTY_RESPONSE

4
Audio / OpenAL32 Credits
« on: October 05, 2018, 07:37:13 am »
I am using the OpenAL32.dll that comes with SFML, but I have read somewhere that I need to include credits for it, or something of that sort. It might've been in the forums, but I can't find it anymore. I am not sure, if this is still the case, and if it is the case, what exactly do I need to put?

5
General / Re: Set Position Of Sprite Depending On Rotation
« on: January 04, 2018, 08:34:54 pm »
The bullets do move, I just commented out the line that moves them so that you can see where they're being drawn. And the rotation isn't the issue either. The issue here is that they're drawn around that point as origin, while they're supposed to be drawn around the player's origin.

What you see in the image is when my character rotates 360 degrees around himself(Full rotation while standing in one position).

I have tested it again, but this time I actually used your way and it worked exactly how I wanted. No more struggles, thank you :D

6
Audio / Re: "Undefined reference to" error when I build my game.
« on: January 03, 2018, 09:12:22 pm »
I have re checked and fixed the issue with the order. Thank you :)

7
General / Re: Set Position Of Sprite Depending On Rotation
« on: January 03, 2018, 09:01:01 pm »
Here is how it looks like with the code above, when I hold LMB and rotate 360 degrees.
The character's origin is in the middle (width/2, height/2). And the bullet's origin is the default, which I think is 0, 0.

8
General / Re: Set Position Of Sprite Depending On Rotation
« on: January 02, 2018, 10:50:19 pm »
I have messed a bit more with the transforms like @Arcade told me, and I have come really close to a solution. But it needs a bit of tweaking.

This works when the bullet sprite is facing 0 degrees. But the bullet sprite seems to rotate relative to a different origin rather than the player's origin.

                //Get points
                float playerR = character.getRotation();
                float playerX = character.getPosition().x;
                float playerY = character.getPosition().y;

                float bulletX = playerX + 15;
                float bulletY = playerY - 80;

                float distX = bulletX - playerX;
                float distY = bulletY - playerY;
               
                //Transforms
                sf::Transform translation;
                translation.translate(distX, distY); //Translate by the distance

                sf::Transform rotation;
                rotation.rotate(playerR, sf::Vector2f(playerX, playerY)); //Give rotation and origin

                sf::Transform transform = translation * rotation; //Combine translartio and rotation into 1 tranform
               
                //I think the problem is here. I am not sure what to pass in as Vector2f.
                sf::Vector2f rotatedVec = transform.transformPoint(sf::Vector2f(playerX, playerY));//Apply transform to vector
 

9
Audio / Re: "Undefined reference to" error when I build my game.
« on: January 01, 2018, 07:43:54 pm »
This is how I linked my libraries:
Quote
sfml-graphics-s
(All dependencies for graphics)
sfml-window-s
(All dependencies for window)
sfml-system-s
(All dependencies for system)
sfml-audio-s
(All dependencies for audio)

Is this the right order?

10
Audio / "Undefined reference to" error when I build my game.
« on: December 28, 2017, 09:44:29 pm »
When I run my game, I get these errors:
Quote
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::FileInputStream::FileInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::FileInputStream::open(std::string const&)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::MemoryInputStream::MemoryInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::MemoryInputStream::open(void const*, unsigned int)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::MemoryInputStream::MemoryInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::MemoryInputStream::open(void const*, unsigned int)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::MemoryInputStream::seek(long long)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::FileInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::open(std::string const&)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::seek(long long)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::~FileInputStream()'|

This is the code that causes this:
sf::SoundBuffer rifleShotBuffer;
if (!rifleShotBuffer.loadFromFile("Audio/RifleShot.wav")) {
   return EXIT_FAILURE;
}
 

Can someone explain why this happens?

11
General / Re: Set Position Of Sprite Depending On Rotation
« on: December 28, 2017, 07:12:55 pm »
Quote
You said you had no luck trying to use trig, but could you be more specific? What did you try and what wasn't working?

I tried multiplying, adding, subtracting, dividing the position, with sine and cosine, nothing worked out well.

Quote
Basically you just need to calculate a relative vector from the origin of your character sprite to the end of the gun, similar to what you have already done in the code you showed us. Then, rotate that vector based on the character's sprite rotation. You can use SFML's Transform class for this if you want to make things easier.

I am really lost, can you show me a code example of what you mean?

Here is what I have came up with,  but I can't figure out how you would rotate the vector using the transform
sf::Transform rotation;
rotation.rotate(character.getRotation());
float x = character.getPosition().x + 15;
float y = character.getPosition().y - 80;
 

12
General / Set Position Of Sprite Depending On Rotation
« on: December 28, 2017, 06:22:01 pm »
I have a bullet sprite, and a character sprite with a gun as a part of it.  When I click, I want the bullet to appear on the end of the gun. This isn't possible for me since the character sprite, changes rotation depending on where the mouse is on the screen.

This would only work if my sprite was rotated at a 0 degree angle.
float x = player.character.getPosition().x + 10;
float y = player.character.getPosition().y - 80;
 

If I changed the rotation, the x and y would not change as they depend on the character's position not rotation.

I have messed a bit with the trigonometry functions(cos, sin) but had no luck.

How would I make the bullet's position depend on the rotation?
I attached both images in case someone needs to look at the dimensions.
Note: Both sprites are scaled down to fit the screen, so the dimensions here aren't the one I am using
CharacterRifle: Scaled down by 0.5
Bullet: Scaled down by 0.03

Pages: [1]
anything