Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SFML random
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aron Nikku
SFML random
Commits
0e939b76
Commit
0e939b76
authored
3 years ago
by
Aron Nikku
Browse files
Options
Downloads
Patches
Plain Diff
Working collisions simulator 1.0
parent
84ab3b98
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.vscode/settings.json
+50
-0
50 additions, 0 deletions
.vscode/settings.json
Collisions/collision3.cpp
+37
-23
37 additions, 23 deletions
Collisions/collision3.cpp
a.out
+0
-0
0 additions, 0 deletions
a.out
with
87 additions
and
23 deletions
.vscode/settings.json
0 → 100644
+
50
−
0
View file @
0e939b76
{
"files.associations"
:
{
"array"
:
"cpp"
,
"atomic"
:
"cpp"
,
"bit"
:
"cpp"
,
"*.tcc"
:
"cpp"
,
"cctype"
:
"cpp"
,
"clocale"
:
"cpp"
,
"cmath"
:
"cpp"
,
"cstdarg"
:
"cpp"
,
"cstddef"
:
"cpp"
,
"cstdint"
:
"cpp"
,
"cstdio"
:
"cpp"
,
"cstdlib"
:
"cpp"
,
"ctime"
:
"cpp"
,
"cwchar"
:
"cpp"
,
"cwctype"
:
"cpp"
,
"deque"
:
"cpp"
,
"map"
:
"cpp"
,
"unordered_map"
:
"cpp"
,
"vector"
:
"cpp"
,
"exception"
:
"cpp"
,
"algorithm"
:
"cpp"
,
"functional"
:
"cpp"
,
"iterator"
:
"cpp"
,
"memory"
:
"cpp"
,
"memory_resource"
:
"cpp"
,
"numeric"
:
"cpp"
,
"optional"
:
"cpp"
,
"random"
:
"cpp"
,
"string"
:
"cpp"
,
"string_view"
:
"cpp"
,
"system_error"
:
"cpp"
,
"tuple"
:
"cpp"
,
"type_traits"
:
"cpp"
,
"utility"
:
"cpp"
,
"fstream"
:
"cpp"
,
"initializer_list"
:
"cpp"
,
"iosfwd"
:
"cpp"
,
"iostream"
:
"cpp"
,
"istream"
:
"cpp"
,
"limits"
:
"cpp"
,
"new"
:
"cpp"
,
"ostream"
:
"cpp"
,
"sstream"
:
"cpp"
,
"stdexcept"
:
"cpp"
,
"streambuf"
:
"cpp"
,
"typeinfo"
:
"cpp"
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
collision3.cpp
→
Collisions/
collision3.cpp
+
37
−
23
View file @
0e939b76
#include
<math.h>
#include
<math.h>
#include
<SFML/Graphics.hpp>
#include
<SFML/Graphics.hpp>
#include
<iostream>
#include
<iostream>
#include
<set>
#include
<vector>
#include
<vector>
int
SIZE
=
500
;
int
SIZE
=
500
;
...
@@ -11,15 +13,10 @@ double pyt(double x, double y) {
...
@@ -11,15 +13,10 @@ double pyt(double x, double y) {
}
}
class
Vector2
{
class
Vector2
{
public:
public:
double
x
;
double
x
;
double
y
;
double
y
;
Vector2
()
{
x
=
0
;
y
=
0
;
}
Vector2
add
(
Vector2
other
)
{
Vector2
add
(
Vector2
other
)
{
Vector2
newVector
;
Vector2
newVector
;
newVector
.
x
=
x
+
other
.
x
;
newVector
.
x
=
x
+
other
.
x
;
...
@@ -124,10 +121,10 @@ class sphere {
...
@@ -124,10 +121,10 @@ class sphere {
newSpeed.x = partOne * partTwoX;
newSpeed.x = partOne * partTwoX;
newSpeed.y = partOne * partTwoY;
newSpeed.y = partOne * partTwoY;
*/
*/
// ALT 2
// ALT 2
double
part1
=
2
*
other
.
mass
/
(
mass
+
other
.
mass
);
double
part1
=
2
*
other
.
mass
/
(
mass
+
other
.
mass
);
double
part2
=
(
(
speed
.
sub
(
other
.
speed
)).
dot
(
pos
.
sub
(
other
.
pos
))
)
/
pow
((
pos
.
sub
(
other
.
pos
)).
abs
(),
2
);
double
part2
=
((
speed
.
sub
(
other
.
speed
)).
dot
(
pos
.
sub
(
other
.
pos
)))
/
pow
((
pos
.
sub
(
other
.
pos
)).
abs
(),
2
);
Vector2
r1
=
pos
.
sub
(
other
.
pos
).
mult
(
part1
*
part2
);
Vector2
r1
=
pos
.
sub
(
other
.
pos
).
mult
(
part1
*
part2
);
newSpeed
=
speed
.
sub
(
r1
);
newSpeed
=
speed
.
sub
(
r1
);
...
@@ -143,13 +140,18 @@ int main() {
...
@@ -143,13 +140,18 @@ int main() {
sf
::
RenderWindow
window
(
sf
::
VideoMode
(
SIZE
,
SIZE
),
"Physics"
);
sf
::
RenderWindow
window
(
sf
::
VideoMode
(
SIZE
,
SIZE
),
"Physics"
);
window
.
setFramerateLimit
(
60
);
window
.
setFramerateLimit
(
60
);
sphere
s1
(
50
,
50
,
30
);
std
::
vector
<
sphere
>
sphereList
;
sphere
s2
(
350
,
200
,
30
);
s1
.
speed
.
x
=
1.5
;
for
(
int
i
=
50
;
i
<
500
;
i
+=
50
)
{
s1
.
speed
.
y
=
0.5
;
for
(
int
j
=
50
;
j
<
500
;
j
+=
50
)
{
s2
.
speed
.
x
=
0
;
sphere
s
(
i
,
j
,
20
);
s2
.
speed
.
y
=
0
;
sphereList
.
push_back
(
s
);
}
}
sphereList
[
0
].
speed
.
x
=
10
;
sphereList
[
0
].
speed
.
y
=
10
;
sphereList
[
0
].
mass
=
500
;
while
(
window
.
isOpen
())
{
while
(
window
.
isOpen
())
{
sf
::
Event
event
;
sf
::
Event
event
;
...
@@ -160,21 +162,33 @@ int main() {
...
@@ -160,21 +162,33 @@ int main() {
}
}
// MOVE
// MOVE
s1
.
move
();
for
(
int
i
=
0
;
i
<
sphereList
.
size
();
i
++
)
{
s2
.
move
();
sphereList
[
i
].
move
();
}
// Collide
// Collide
Vector2
speed1
=
s1
.
sphereCollision
(
s2
);
for
(
int
i
=
0
;
i
<
sphereList
.
size
();
i
++
)
{
Vector2
speed2
=
s2
.
sphereCollision
(
s1
);
for
(
int
j
=
i
;
j
<
sphereList
.
size
();
j
++
)
{
if
(
i
!=
j
)
{
s1
.
setSpeed
(
speed1
);
Vector2
speed1
=
sphereList
[
i
].
sphereCollision
(
sphereList
[
j
]);
s2
.
setSpeed
(
speed2
);
Vector2
speed2
=
sphereList
[
j
].
sphereCollision
(
sphereList
[
i
]);
sphereList
[
i
].
setSpeed
(
speed1
);
sphereList
[
j
].
setSpeed
(
speed2
);
//std::cout << speed2.x << " " << speed2.y << std::endl;
//std::cout << i << " " << j << std::endl;
//std::cout << sphereList[1].pos.x << " " << sphereList[1].pos.y << std::endl;
}
}
}
window
.
clear
();
window
.
clear
();
// DRAW
// DRAW
s1
.
draw
(
window
);
for
(
int
i
=
0
;
i
<
sphereList
.
size
();
i
++
)
{
s2
.
draw
(
window
);
sphereList
[
i
].
draw
(
window
);
}
window
.
display
();
window
.
display
();
}
}
...
...
This diff is collapsed.
Click to expand it.
a.out
+
0
−
0
View file @
0e939b76
No preview for this file type
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment