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

Pages: 1 2 3 [4] 5
46
Graphics / Re: Using ::transform to rotate vertices
« on: April 09, 2020, 10:49:22 pm »
The matrix is just a standard mathematical matrix and the calculations are standard ones too. Transform does all the things you expect a mathematical matrix to do.

To understand the actual, underlying matrix and how they work, there's a lot of good explanations here:
https://en.wikipedia.org/wiki/Matrix_(mathematics)
(particularly this part: https://en.wikipedia.org/wiki/Matrix_(mathematics)#Linear_transformations )
https://en.wikipedia.org/wiki/Square_matrix
Yes, you actually already linked this link and i have read a bit of it,
So my question here, to use this :
[cos(A)     -sin(A)]
[sin(A)      cos(A)]

I will be doing something like this?
#define SIN(x) sin(x * 3.141592653589/180)
#define COS(x) cos(x * 3.141592653589/180)
...
int main()
{

// defining a random shape
sf::RectangulareShape ...
..
float A=25.

sf::Transform t(COS(A) -SIN(A) 0,
                 SIN(A), COS(A), 0,
                 0, 0, 0);

...
..
window.draw(shape,transform)
 

?
I still don't see how it is used. (I know where the matrix with cos and sin came from, i spent few time writing on a paper and understanding it btw)

I just don't see where the sf::transform intervenes, sincerely sorry with my lack on understanding for this specific point.

47
Yes here it is
void contract(sf::VertexArray &V,float ExpandValue,char item,int NumberOfVertices)
{
    if (V.getVertexCount()==4)
  {
V[0].position.x=V[0].position.x+ExpandValue; V[0].position.y=V[0].position.y+ExpandValue;
V[1].position.x=V[1].position.x-ExpandValue; V[1].position.y=V[1].position.y+ExpandValue;
V[2].position.x=V[2].position.x-ExpandValue; V[2].position.y=V[2].position.y-ExpandValue;
V[3].position.x=V[3].position.x+ExpandValue; V[3].position.y=V[3].position.y-ExpandValue;

NewXCenterShape=V[1].position.x-V[0].position.x;
NewYCenterShape=V[2].position.y-V[1].position.y;

...
...
 
It's the part about the 4 vertices in the center (the rectangle)

And then called the function :
sf::VertexArray CenterObj(sf::Quads,4);
    CenterObj[0].position=sf::Vector2f(300,300);
    CenterObj[1].position=sf::Vector2f(400,300);
    CenterObj[2].position=sf::Vector2f(400,400);
    CenterObj[3].position=sf::Vector2f(300,400);
    CenterObj[0].texCoords = sf::Vector2f(80.f, 76.f);
    CenterObj[1].texCoords = sf::Vector2f(122.f, 76.f);
    CenterObj[2].texCoords = sf::Vector2f(122.f, 122.f);
    CenterObj[3].texCoords = sf::Vector2f(80.f, 122.f);

...
...
if(event.type==sf::Event::KeyPressed&&event.key.code==sf::Keyboard::C)
            {
                float ContactValue=1;
               contract(CenterObj,ContactValue,'e',4); //here the char variable is not important, it is not used, 'e' can be replaced
..
..

 

48
Graphics / Re: Using ::transform to rotate vertices
« on: April 09, 2020, 10:25:21 pm »
Quote
1) How is a 3x3 matrix relevant when we are only working on 2D spaces (sf::window has x and y coordinates only)?
Translations require an additional dimension.

Quote
2) is it possible to use the matrix 2x2 that i mentionned (with cos and sin, just above) with the "transform" class?
What do you think Transform::rotate does? ;)

Quote
3) If you have anything to add, or examples about this transform class that is different from what is said on the tutorial, i'd like to hear please.
If you feel like the documentation or tutorial is lacking important information, I'd like to hear please.

You should really take one or two days to read the documentation and tutorials (and other available resources) carefully. You ask too many questions, I have the feeling that you're not trying enough by yourself ;)
Maybe you are right about me needing to explore this more but i "feel" you are not (i may be wrong), because :
I actually had an answer about a month ago an the subject "do this three features exist?" and i spent whole lot of time RE-READING most tutorials, believe me. Proof i found myself asking if there was a full class diagramm for SFML (you can find it on the suggestions forum), because i was rewrite by hand all the functions i found and try to memorize them.


And ONLY when i suceeded in using the matrix that has been suggested to me a month ago.. i felt "free" to ask my questions. ( you can see that i separated my posts on the graphics forum by weeks). I would not ask this questions if i did not try hard to understand.


Quote
If you feel like the documentation or tutorial is lacking important information, I'd like to hear please.

Yes i feel there is 0 example for the use of a matrix with transform class, i have no idea what the matrix does within the transform and how it works, eventhough i understand where the matrix 
[cos(A)     -sin(A)]
[sin(A)      cos(A)]
came from. I know its (NewCoordinaters) = Matrix * (OldCoordinates). So i don't know if i lack more maths maybe. I just don't see what the 3x3 matrix does and i have not encoutenred "any" example using it. Not do i know how to implement the 2x2 matrix above on the class transform.
I managed to write this code :
void pivot(sf::VertexArray &V,float angle,sf::Vertex CenterCoordinates,int NumberOfVertices) // number of points
{
    for(int i=0;i<NumberOfVertices;i++)
    {
           
          OldPoint_x_shifted=V[i].position.x-CenterCoordinates.position.x;
          OldPoint_y_shifted=V[i].position.y-CenterCoordinates.position.y;
          NewPoint_x_shifted=COS(angle)*OldPoint_x_shifted-OldPoint_y_shifted*SIN(angle);
          NewPoint_y_shifted=OldPoint_x_shifted*SIN(angle)+OldPoint_y_shifted*COS(angle);
          V[i].position.x= NewPoint_x_shifted + CenterCoordinates.position.x;  //  NewPoint_x FINAL DESTINATION
          V[i].position.y= NewPoint_y_shifted + CenterCoordinates.position.y;  //  NewPoint_y FINAL DESTINATION
          cout << "i = " << i <<endl;

    }

}
Yet i don't see how to do with the class transform, you should just tell me.
Quote
What do you think Transform::rotate does?
It works for shapes but not for vertices.

Let's take this example from the tutorial  :

I still wonder to this day what each part of the 9 points of this matrix does. And how it applies to my (x,y) coordinates for my shape.

This example is perfectly understood :
sf::Transform t;
t.translate(10.f, 100.f);
t.rotate(90.f);
t.translate(-10.f, 50.f);
t.scale(0.5f, 0.75f);
It's perfectly fine, i tested it direclty.

I have no game design previous knowledge nor lot of experience with C++ so the matrix of transform might be for all of you obvious but not for me at least not through reading the turorial.

Let me try to give feedback for the turotial i have read twice :


I think i might not know how to do the inheritence from transformable class, nor will i know to use the matrix function anyway. I can't wait to know the answer for my questions and feel stupid and see how easy it was, i am really excited to know the answers.




49
You don't want to react to events, but rather check the keyboard state at every iteration of your game loop. Read the documentation and tutorials again, this is well explained ;)

https://www.sfml-dev.org/tutorials/2.5/window-inputs.php

Ah perfect,
So you the code should be like this :


if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
{
                pivot(RightObj,ang,sf::Vector2f(saveCenter1,saveCenter2),3);
                pivot(LeftObj,ang,sf::Vector2f(saveCenter1,saveCenter2),3);
                }

So you use events only to check for important events that have to happen once, like jumping
Quote
This event is the one to use if you want to trigger an action exactly once when a key is pressed or released, like making a character jump with space, or exiting something with escape.
Quote from another tutorial actually : https://www.sfml-dev.org/tutorials/2.5/window-events.php

Thanks Laurent.

50
General / Re: Hide the files of your "game" or "app"
« on: April 09, 2020, 09:00:14 pm »
Yes, let's say i made a game with "secrets" and suprises.
I don't want players to discover all the images and sounds and musics that the game has to offer.
Do you know how can that be done? I am using CodeBlocks.

51
Hello again,
I made a function to reduce or contract the size of a shape made of vertices :
void contract(sf::VertexArray &V,float ExpandValue,char item,int NumberOfVertices)

It seems to be working, but i noticed the shape start to expanding after it has reached a size of 0 , like this :
https://gfycat.com/fr/illfatedesteemedenglishpointer

Any idea about this phenomenon?
The window is a (800,800).

Thanks
P~


52
Hello,
I made a program where you can press the arrow keys to move an item, and if you press "Q" the item would rotate,

I noticed i could not have the item MOVE and rotate at the same time if i pressed an arrow key and 'Q' at the same time. Is that normal?

Here is the code :


while (window.isOpen())
    {

...
...
        sf::Event event;
        while (window.pollEvent(event))
        {
               if(event.type==sf::Event::KeyPressed&&event.key.code==sf::Keyboard::Q)
            {
                pivot(RightObj,ang,sf::Vector2f(saveCenter1,saveCenter2),3);
                pivot(LeftObj,ang,sf::Vector2f(saveCenter1,saveCenter2),3);
       
               

               // save= ang+save;


            }
            if(event.type==sf::Event::KeyPressed&&event.key.code==sf::Keyboard::Right)
            {
   
                shiftVertex(RightObj,10,'r',3);
                shiftVertex(LeftObj,10,'r',3);


            }


...
...
}

 

It's quiiite frustrating, i want to make a reeally dynamic game where you can press many keys and ave many actions happen.

53
Feature requests / Re: Full UML Class Diagram for SFML?
« on: April 09, 2020, 03:22:17 pm »
Oh i see you have done it yourself, and have used the doxygen tool? Sorry i hadnt seen your answer before,

As for the modules not being real things, yes i figured it out quickly, when i was "drawing" and writing everything on a piece of paper. And yes i know i dont have to know all the details, but in reality it helps me. The more i know the more "expanded" and "rooted" can your brain be, i like to have an image of everything rather than wondering if "KeyEvent" or "Keyboard" are related or not.

Thanks a bunch

54
General / Hide the files of your "game" or "app"
« on: April 09, 2020, 02:33:26 pm »
Hello,
I am very excited for learning SFML, and still have many questions,
On a video tutorial, i saw how a compiled programme through "release" option, could be generated and be distributed, the tutorial mentionned not to forget any data files (font/image/texture/musics).

And i tried it, i could send a programme.exe + the files + the .dll files all in one package, the receiver extracted all and was able to test my programme.

Now is there a way to hide all the files/data from the user of the programme?

55
Java / Android studio - java - sfml
« on: April 09, 2020, 02:28:39 pm »
Hello,
I read JSFML developpent has stoped, i plan to learn java when i have time, would it still be possible then to use sfml on JAVA and android studio to make little smartphone app games?

Thanks,
Good day

56
Audio / Re: Can't play 2 "musics" on one game?
« on: April 09, 2020, 02:22:40 pm »
Hello Mr Hapax,
...
Thanks Hap
I'm not a mister but you are welcome :)

You are amazing thanks for all the good work.



In case you want something a little more 'automatic', feel free to use:
https://github.com/Hapaxia/SfmlSoundSystem
It allows multiple musics and will also 'fade' from one to the next when you start a new one (you get to choose how long that takes!)
I also allows sounds to be played from there. Useful for sound effects.
It stores the resources inside it so this can be considered a sound resource manager that can also play them too!

So many things to learn, it's great! I don't use github alot...yet, i am supposed to download all the files, and then add the libraries (i am using codeblocks) the same way i have added the graphics and audio module, then not forget to to an "#include" on the code?

57
Graphics / Using ::transform to rotate vertices
« on: April 09, 2020, 01:30:55 pm »
Hello,
My first big challenge as a newcomer was to make a concave shape rotate, thanks to A_Sentient_Tomato for the right matrix he shared (https://en.sfml-dev.org/forums/index.php?topic=26984.0), and especially to Hapax for providing this link : https://www.geeksforgeeks.org/2d-transformation-rotation-objects/

https://gfycat.com/fr/realisticwarpedamurstarfish

I used this matrix :
[cos(A)     -sin(A)]
[sin(A)      cos(A)]
Okay, and i know how we got it and what it means
I did not use any transform class , i used only codes of this form :
Quote from: A_Sentient_Tomato
let's say your shape's vertices are {(x,y), (x1, y1), (x2,y2)}
create a new shape with vertices at {(x-C, y-C), (x1-C, y1-C), (x2-C, y2-C)}
_______________________________________________________________
Topic :
Now my problem is this "transform" class thing and its functions https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transform.php

____________________________________________________________
It has a 3x3 matrix i saw, here are my questions :

1) How is a 3x3 matrix relevant when we are only working on 2D spaces (sf::window has x and y coordinates only)?

2) is it possible to use the matrix 2x2 that i mentionned (with cos and sin, just above) with the "transform" class?

3) If you have anything to add, or examples about this transform class that is different from what is said on the tutorial, i'd like to hear please.

(My next challenge is to make vertices shapes "expand" in size.....)

Thanks for any enlightenment.

58
Graphics / Re: Do these three features exist?
« on: April 09, 2020, 01:14:55 pm »
I have finally managed to achieve it! :)
https://gfycat.com/realisticwarpedamurstarfish
I will make a now post and link this one, to try to understand the transform matrix and differents ways of using it, because i did not use any "transform" to achieve this concave shape rotation.

59
Audio / Re: Can't play 2 "musics" on one game?
« on: April 06, 2020, 11:09:57 pm »
If you tell a music to play when it's already playing, it will restart from the beginning.
Hello Mr Hapax,
Yes indeed, i actually noticed it when the function was inside the while.
But after that, the function was called Soo fast that it had not the time to play, i thought the game could not handle 2 musics..
Here is the solution in case anyone browse this forum in 2022 :
if(Music2.getStatus()==sf::Sound::Stopped&&Music3.getStatus()==sf::Sound::Stopped)
            {Music3.play();}
Meaning the music3 will not play only when the music2 has stopped, AND music3 will not play either if its not in a state of "stopped").
Thanks Hap

60
Audio / Can't play 2 "musics" on one game?
« on: April 06, 2020, 12:32:08 pm »
Hello,
While experimenting and making a little game, i wanted to start the game with a first music and further it at some point with a second one.

The musics work fine if the function music.play() is called before the while(window.isOpen()), but if i put a music.play() inside this "while" the music will not..play correctly. It will stop at every move the mouse cursor make. Meaning if the mouse hasn't moved the music plays, if the cursor moves, it will restart.

I decided then, to put a bool variable inside the  "while", and call the function music.play() after the while (after : while(window.isOpen() ) ). The condition would be for the bool variable to be true.

It does not work!

 bool part2=0;
    bool cond1=0;
    bool part3=0;
...
..

///MUSIC
    sf::Music Music2;
    if(Music2.openFromFile("data/music2.ogg")==0)
    {
        return 1;
    }

    Music2.setVolume(30);
    Music2.setLoop(true); ///
    Music2.play();
    //second music
    sf::Music Music3;
    if(Music3.openFromFile("data/music3.ogg")==0)
    {
        return 1;
    }
    Music3.setVolume(30);
    Music3.setLoop(true); ///
    Music3.play();
    Music3.pause(); /// i tried here to make the music start before the while then pause it, to see if could just resume the music later.

while (window.isOpen())
    {


        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            if (event.type== sf::Event::MouseButtonPressed && event.mouseButton.button ==sf::Mouse::Left)
          {
              ....
              ...
                  {if(position.y<=446&&position.y>=263){if(money>=300&&weight<=450){part2=0;cond1=1;money=money-300;}}}
               
                .....


        Music3.play(); /// would do the problem discribed above

        }

        ///LOGIC
        ....
        ...
          //  if(weight<=450&&cond1==0){part2=1;}

            if(cond1==1){part3=1; part2=0;}//Music2.stop();Music2.play();}  ... // it did not work here either
           // if(Music2.getStatus()==sf::Sound::Stopped)
            //{Music3.play();}  // does not play
             ...
..



 

Pages: 1 2 3 [4] 5