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

Author Topic: Do these three features exist? [Solved]  (Read 6372 times)

0 Members and 1 Guest are viewing this topic.

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Do these three features exist? [Solved]
« on: March 08, 2020, 08:42:14 am »
Hello,
I was very exciting to discover SFML and the world of programming,
Now i have few quick questions if someone expert knows the answer

1) Is it possible to draw an object (with paint) and use some kind of tool/programm to transform it into a real in game item with the exact shape you have drawn?  (meaning the item will have the collision area you have drawn)

2) Is there a function to merge items/objects into 1 item? (example : 2 circles meet each other (one circle hits the other), resulting in making one single item with a shapre of "8")

3) Is it possible to give an item, let's say a rectangle, 4 different kind of interactions with other items depending on which side of the rectangle was hit by another item? (So if a user rotated the rectangle to make it hit with the side number 2 or 3, the result would change, my question is, can SFML differenciate between the 4 sides of the rectangle?)

Thank you
And a have a good day
P-
« Last Edit: April 09, 2020, 01:15:16 pm by Power »

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Do these three features exist?
« Reply #1 on: March 08, 2020, 10:05:31 am »
Hello,
I was very exciting to discover SFML and the world of programming,
Now i have few quick questions if someone expert knows the answer

1) Is it possible to draw an object (with paint) and use some kind of tool/programm to transform it into a real in game item with the exact shape you have drawn?  (meaning the item will have the collision area you have drawn)

2) Is there a function to merge items/objects into 1 item? (example : 2 circles meet each other (one circle hits the other), resulting in making one single item with a shapre of "8")

3) Is it possible to give an item, let's say a rectangle, 4 different kind of interactions with other items depending on which side of the rectangle was hit by another item? (So if a user rotated the rectangle to make it hit with the side number 2 or 3, the result would change, my question is, can SFML differenciate between the 4 sides of the rectangle?)

Thank you
And a have a good day
P-

SFML is more a wrapper to make things easier rather than an engine. With this said:

1) The shape u drawn will always be a perfect rectangle, since there are pixels with alpha 0, but not non-existent, and SFML takes a sprite as a rectangle. On the second hand SFML does not have a collision system. What is rn available is just classic math boundary checking. U should implement ur own system if u want advanced collision

2) I don't see why wouldn't do that urself. Just delete one and modify the other one, no need for such techniques like merging

3) U can check what margin was been hit, taking in account sprite rotation

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Do these three features exist?
« Reply #2 on: March 08, 2020, 01:14:33 pm »
Hi,
1) Yes that's i thought, so every item i draw will be a rectangle, i wondered with there was a program that could transform any drawing, by looking at the pixels valors (0 or different from 0), into a script describing multiple items (triangles and rectangles) that form in the end one final complicated item similar to the one i draw in paint.

2) Fx8qkaoy, well i wanted to make it happen inside the program, let's say we have an item that collects other items, first item can be moved using keyboard, other items cant, until they are touched by first item, first item becomes bigger  and thus the played can now move first item+ new item attached to it.
That was the plan.

3) Yes i see, thank you.

I am just starting SFML after folowwing a tutorial, but i realise a lot of research and experimentation has to be done. It's great to have this anyways.
I am prety sure there is still a lot i don't know

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Do these three features exist?
« Reply #3 on: March 08, 2020, 05:28:39 pm »
For more complex collision systems, you can also use Box2D, but it doesn't necessarily make things easier.
As Fx8qkaoy said, SFML is more a framework that allows you to do whatever you want, but it's still you who has to write things.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Do these three features exist?
« Reply #4 on: March 08, 2020, 07:09:59 pm »
I did not know about 2dBox. Thanks

I understand,

question for you though, is there a place/list somewhere where people share their more complexe functions/objects made with simpler SFML functions?

Not that i don't want to try making my own more complicated fonctions it's part of the fun of course.

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Do these three features exist?
« Reply #5 on: March 08, 2020, 07:27:02 pm »
This is what i was going for before making this thread, i wanted to make the item shown in my profile picture, and make it :
1) Rotate
2) Make the item not like a full rectangle, it means its boundaries must be like the picture

So i thought about making multiple little rectangle/triangles and bind them to make the item, but then how can i rotate all the binded items at once without losing exact shape of the item, this is where i am stuck right now.

A_Sentient_Tomato

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Do these three features exist?
« Reply #6 on: March 08, 2020, 08:25:18 pm »
An easy way to do this is with a matrix:
let's say you have a center of rotation, C, and an angle of rotation, A.
your shape is made of a bunch of little shapes - you can just apply this transformation to each one.
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)}
apply the 2D rotation matrix (oh boy how do I format this):
[cos(A)     -sin(A)]
[sin(A)      cos(A)]
to each one of the new shape's vertices and then just add C back to each one.

Apply this to every one of your shapes and they will rotate exactly!

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Do these three features exist?
« Reply #7 on: March 08, 2020, 08:28:18 pm »
If u want to move multiple items together, just have all the related items stored somewhere, and when moving one of them, move everyone. The same for rotation. I think I know what u mean that the shape after rotation is not the right one. It has to do with rotation origin. If I'm not wrong, SFML allows u to set origins outside of sprite boundaries, which means u need to set child items origins to the main one. If SFML doesn't allow it, but I doubt, after every rotation u have to reposition the items (which probably is what Sentinent said)

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Do these three features exist?
« Reply #8 on: March 08, 2020, 09:52:59 pm »
An easy way to do this is with a matrix:
let's say you have a center of rotation, C, and an angle of rotation, A.
your shape is made of a bunch of little shapes - you can just apply this transformation to each one.
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)}
apply the 2D rotation matrix (oh boy how do I format this):
[cos(A)     -sin(A)]
[sin(A)      cos(A)]
to each one of the new shape's vertices and then just add C back to each one.

Apply this to every one of your shapes and they will rotate exactly!
Amazing. I am going to try this then, i hope it works.

If u want to move multiple items together, just have all the related items stored somewhere, and when moving one of them, move everyone. The same for rotation. I think I know what u mean that the shape after rotation is not the right one. It has to do with rotation origin. If I'm not wrong, SFML allows u to set origins outside of sprite boundaries, which means u need to set child items origins to the main one. If SFML doesn't allow it, but I doubt, after every rotation u have to reposition the items (which probably is what Sentinent said)
Yes as i am just learning SFML, i did not know about these details.
Thank you
I might give an update when i do it.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Do these three features exist?
« Reply #9 on: March 08, 2020, 11:12:30 pm »
Some community members have written libraries for certain things.

Thor: https://bromeon.ch/libraries/thor/
SelbaWard: https://github.com/Hapaxia/SelbaWard/wiki
Plinth: https://github.com/Hapaxia/Plinth
RichText: https://github.com/skyrpex/RichText
ImGui-SFML: https://github.com/eliasdaler/imgui-sfml

If you google a bit, you can find lots of related code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Do these three features exist?
« Reply #10 on: March 25, 2020, 01:44:46 am »
Some community members have written libraries for certain things.

Thor: https://bromeon.ch/libraries/thor/
SelbaWard: https://github.com/Hapaxia/SelbaWard/wiki
Plinth: https://github.com/Hapaxia/Plinth
RichText: https://github.com/skyrpex/RichText
ImGui-SFML: https://github.com/eliasdaler/imgui-sfml

If you google a bit, you can find lots of related code.
It's really great to all this to dive in. SFML is really great.

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Do these three features exist?
« Reply #11 on: March 25, 2020, 01:49:49 am »
An easy way to do this is with a matrix:
let's say you have a center of rotation, C, and an angle of rotation, A.
your shape is made of a bunch of little shapes - you can just apply this transformation to each one.
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)}
apply the 2D rotation matrix (oh boy how do I format this):
[cos(A)     -sin(A)]
[sin(A)      cos(A)]
to each one of the new shape's vertices and then just add C back to each one.

Apply this to every one of your shapes and they will rotate exactly!

Hello, sorry i am trying to use this only today (i have been busy),
Whay do you mean by the 2D rotation matrix?
Yoo described three vertices and then showed a matrix containing 4 operations,
I see on the documentation : https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transformable.php
only one 2 rotation functions : setRotation (float angle) and rotate (float angle), both have only one argument. Could you expand please?
If anyone has the answer, feel free.. since A_Sentient_Tomato is nota regular user he might not see this.

(Remember i know some math but mostly i am a free c++ learner.)
« Last Edit: March 25, 2020, 09:36:07 am by Power »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Do these three features exist?
« Reply #12 on: March 26, 2020, 10:25:20 pm »
You can sf::Transform for the transformation matrix, if you're fine with matrices.
Even if not, you can still use them. You can get them from transformables*, use them for calculations/modifications and then apply them to your own vertices (for your own tranformable, for example).

*
Transform
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transformable.php#a7f7c3f0bab3f162b13613904fbdbb9ad
Inverse Transform
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transformable.php#ab18b25f51263252ff3811465eb7e9fb1
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Do these three features exist?
« Reply #13 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.

 

anything