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

Pages: [1] 2 3
1
Oh, I did notice that mistake and fix it while moving everything over to the main file, didn't realize it was the actual source of the problem, I guess I'll go move the code back if I feel like it's worth it.

Oh well, the more you learn, thanks!

2
Yup, moving everything back to the main.cpp file fixed the problem, and also fixed another problem I was having where I couldn't interact with the ImGui widgets if I clicked off the SFML window.

So yeah, moving those 5 lines to a separate file to have less code in the main.cpp files defiantly wasn't worth it.

As for the ImGui-SFML issue tracker, well, there are barely any posts on there, and all of the posts made during 2021 either have one or no replies so it seemed pretty dead to me.

3
Yeah I already have that line included in another file along with the rest of the SFML window setup:

#include "Window.h"

sf::RenderWindow w(sf::VideoMode(1000, 700), "Window");
sf::Event e;
window_methods mw;

void window_methods::close_window() {
        ImGui::SFML::ProcessEvent(e);
        while (w.pollEvent(e)) {
                switch (e.type) {
                case sf::Event::Closed:
                        w.close();
                        break;
                }
        }
}

4
So I posted this on the ImGui issues tracker but they closed it and told me to post it on the SFML-ImGui issues tracker, except that one is inactive so this is my last hope to get an answer...

I'm using ImGui with SFML and I'm trying to make a text-box that stores a file path.



I followed what this post did: (https://github.com/ocornut/imgui/issues/2487#issuecomment-482474783) but what keeps happening is that the textbox will start repeating the first character typed into it until the entire buffer is filled with the same repeated character, example:





I also tried moving the buffer inside the loop and got the same result, what am I doing wrong?

5
Graphics / Re: Can't release 64x builds.
« on: January 23, 2022, 02:50:25 pm »
Alright then, I already have the 32-bit template ready which is what I've been working with, so I'll make a 64-bit one if I end up needing it, thank you so much, this was extremly informative and helpful.

6
Graphics / Re: Can't release 64x builds.
« on: January 23, 2022, 10:39:37 am »
I did specify the include paths for 64-bit but it wasn't enough, I'm guessing it's a linking issue, I'm planning on re-installing SFML and creating a new template from scratch that will allow me to compile for both 64 and 32 bit, I'm a bit confused as to which version of the library (32-bit or 64-bit) I'd want to download though, which one will allow me the option to compile for both platforms?

Sorry if this is an amateur question, I tend to focus on the process of coding itself so I often neglect learning about things like this.

7
Graphics / Re: Can't release 64x builds.
« on: January 22, 2022, 02:28:03 pm »
Well, after struggling with this for a bit I thought maybe I should re-install the library from scratch and make sure I set the same configurations to all platforms from the beginning and see if that fixes the problem, but on the download page it says it's recommended that you compile for 32-bit machines to reach the biggest possible audience, since a 64-bit machine can perfectly run a 32-bit app, so I guess I don't have to do any of this after all, should've done my research instead of assuming compiling to 64-bit would have some hidden benefit.

Well, thanks either way, hope this helps someone else in the future.

8
Graphics / [SOLVED] Can't release 64x builds.
« on: January 22, 2022, 01:15:41 am »
Hey, it's been a while, since I've been using SFML casually this whole time, I didn't really bother with project configurations, and as such I've been working with 32-bit apps this whole time, but when I recently tried switching to 64-bit, I got a "cannot open source file" error for all SFML headers.





Any idea what that's about?


9
General / Setting up an SFML with Box2D in Visual Studio (2019).
« on: November 16, 2020, 12:33:35 pm »
I already had an SFML template project that I've been using for a while, and now I want to add Box2D to it, but after I thought I did everything correctly, I get external errors whenever I write anything using the Box2D library, I think the problem might be related to the additional dependencies, all the tutorials I found were outdated,can anyone walk me through the process of setting up the latest version of Box2D with SFML in Visual Studio (2019)?

10
Graphics / Re: I can't get the math right. [SOLVED]
« on: October 04, 2020, 11:25:29 am »
Again, I know that, but this still doesn't answer my question as to why is the rectangle is positioned where it is without me specifying an angle, remember, without me specifying an angle, the rectangle would be rotating around the circle with the same angle the sprite is rotating at.

EDIT: I found this exactly after typing this reply, but it turns I forgot I set the entity sprite to be rotated at a 90 degrees angle so that the gun would be aligned with the mouse cursor, that must be it.

void Player::mouse_controls(sf::Vector2f cursor) {
        sf::Vector2f direction;
        direction.x = entity_sprite.getPosition().x - cursor.x;
        direction.y = entity_sprite.getPosition().y - cursor.y;
        float angle = atan2(direction.y, direction.x) * 180 / 3.14;
        entity_sprite.setRotation(angle - 90);// <-------
        std::cout << angle << std::endl;
}
 

11
Graphics / Re: I can't get the math right.
« on: October 03, 2020, 10:42:40 pm »
Nope, nevermind, apparently all it took was to was to divide the rotation by 180 and multiply it by 3.14 (Which is something I DID actually try, but I think I messed up and typed it outside the parenthesis of the cos/sin functions, as opposed to inside, where it's supposed to be)...

So now the line looks like this:

test.setPosition(sf::Vector2f(player.scope.getPosition().x + cos(player.scope.getRotation() / 180 * 3.14) * 25, player.scope.getPosition().y + sin(player.scope.getRotation() / 180 * 3.14) * 25));

And just like that:

I'm facepalming so hard right now...

Now, there is something odd, in this updated line, the part where I add 90 degrees to the scope's rotation has been removed, but as you can see the rectangle is still fixed at 90 degrees to the direction of the player, and while that is what I want, I'm not sure why it's that way...
No big deal though, if I want a different angle I can just add it to the rotation just like I did in the original post.

The techniques you posted can still come in handy down the line, since I'm planing on learning more about both graphics as well data structures and algorithms, just so you know your effort wasn't really in vain, thank you!

12
Graphics / Re: I can't get the math right.
« on: October 02, 2020, 08:33:03 pm »
I already figured that out when getting the character to follow the cursor, I simply used atan2 to calculate the angle then multiplied it by 180/3.14 to get the angle in degrees, but here when using sine and cosine it doesn't seem to be that straight forward.

13
Graphics / I can't get the math right. [SOLVED]
« on: October 02, 2020, 07:30:14 pm »
So I have a player character sprite, that rotates to follow the mouse cursor around, and a circle centered around the cursor:



I'm trying to calculate the coordinates of one of the points of the circle, that changes depending on the rotation of the player character, where the argument of the point will be equal to the rotation of the player character +90 degrees, so let's say I want to position a 10x10 blue rectangle shape at this point, it will looks like this:

If the player's rotation is equal to 180 => the point will have an argument of -90:

If the player's rotation is equal to 90 => the point will have an argument of 180:

If the player's rotation is equal to 135 => the point will have an argument of -135:


And, I'm half way there, here is my attempt at calculating the position of the rectangle (in the main loop), knowing that:

test is the blue square.
scope is the circle
25 is the radius if the circle (scope)
scope's rotation is literally equal to that of the player character:
scope.setRotation(entity_sprite.getRotation());

So the player character's rotation and the circle's rotation are interchangeable.

 test.setPosition(sf::Vector2f(player.scope.getPosition().x + cos(player.scope.getRotation() + 90) * 25, player.scope.getPosition().y + sin(player.scope.getRotation() + 90) * 25));

It...sort of works:


It doesn't appear in the gif because of low frame-rate, but the rectangle is spinning around the circle in the right directions, but it's doing it too quickly, I've had a similar problem when coding the character to follow the cursor, but I solved it by multiplying the angle outputted by the atan2 function by by 180/3.14, it doesn't seem to be as straight forward here...

So, how do I calculate the coordinates of this point correctly?

14
Graphics / Re: Setting the origin of sf::ConvexShapes.
« on: September 27, 2020, 06:51:49 pm »


I guess it was that simple huh? This is my first time working with convex shapes, hence the confusion.

Thank you!

15
Graphics / Setting the origin of sf::ConvexShapes. [SOLVED]
« on: September 27, 2020, 03:07:49 pm »
Gee I didn't think I'd be back here this soon, but this time it's a simple problem:

I'm trying to make Boids, and I wrote this class for a single boid:

Boid.h:
class Boid {
public:
        sf::ConvexShape shape;
        Boid(sf::Vector2f head) {// The 'head' parameter stores the coordinates of the "head" of the boid, with other two points being relative to the head.
                shape.setPointCount(3);
                shape.setPoint(0, head);
                shape.setPoint(1, sf::Vector2f(head.x - 5, head.y + 20));
                shape.setPoint(2, sf::Vector2f(head.x + 5, head.y + 20));
                shape.setFillColor(sf::Color::Blue);
        }
};
 
And then wrote this code in the main file to generate a 100 boids with random positions within the confines of the window (with 'w' being the name of the sf::RenderWindow):

main.cpp:
std::vector<Boid>boids;
        for (int i = 0; i < 99; i++) {
                float spawn_x = rand() % w.getSize().x;
                float spawn_y = rand() % w.getSize().y;
                float angle = rand() % 360;
                boids.push_back(Boid({ spawn_x,spawn_y }));
        }
 

The result:


Ok, so far so good, but then I tried getting all the boids to rotate, and after messing around with for loops for a bit, I realized they were rotating around the top left corner, meaning that all of their origins were set to the point(0,0), so I kept that in mind and trying to set the origin of each boid to it's center modifying the code to make each boid have a random rotation when spawned:

The code now looked like this:

Boid.h:
class Boid {
public:
        sf::ConvexShape shape;
        Boid(sf::Vector2f head, float angle) {// Added the 'angle' parameter which stores the rotation of the boid.
                shape.setPointCount(3);
                shape.setPoint(0, head);
                shape.setPoint(1, sf::Vector2f(head.x - 5, head.y + 20));
                shape.setPoint(2, sf::Vector2f(head.x + 5, head.y + 20));
                //shape.setOrigin(sf::Vector2f(shape.getPoint(0).x, shape.getPoint(0).y + 10));
                shape.setOrigin(sf::Vector2f(head.x, head.y + 10));
                shape.setRotation(angle);
                shape.setFillColor(sf::Color::Blue);
        }
};
 

main.cpp:
std::vector<Boid>boids;
        for (int i = 0; i < 99; i++) {
                float spawn_x = rand() % w.getSize().x;
                float spawn_y = rand() % w.getSize().y;
                float angle = rand() % 360;
                boids.push_back(Boid({ spawn_x,spawn_y }, angle));
        }
 

The result:


From that weird blue quadrant in the corner, you can tell the boids do have different rotations, and they do have their origins in their centers(I tried changing the origins to the positions of the heads of each boid, and the quadrant became larger, so this part is definitely working correctly), but why are they all positioned at the point(0,0)?
And why don't convex shapes have "local" origins like other drawables such as Sprites and RectangleShapes?

Pages: [1] 2 3