Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
electric-field
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
repos.tanguy.cavagna
physics
electric-field
Commits
5b006cbf
Commit
5b006cbf
authored
3 years ago
by
tanguy.cavagna
Browse files
Options
Downloads
Patches
Plain Diff
Added left click for + charge and right click for - charge & better random q
parent
95eb3773
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
charge/charge.c
+4
-0
4 additions, 0 deletions
charge/charge.c
charge/charge.h
+8
-0
8 additions, 0 deletions
charge/charge.h
main.c
+8
-3
8 additions, 3 deletions
main.c
with
20 additions
and
3 deletions
charge/charge.c
+
4
−
0
View file @
5b006cbf
...
@@ -69,4 +69,8 @@ bool compute_p_next(charge_t *charges, int num_charges, double eps,
...
@@ -69,4 +69,8 @@ bool compute_p_next(charge_t *charges, int num_charges, double eps,
charge_t
charge_create
(
double
q
,
vec2
pos
)
{
charge_t
charge_create
(
double
q
,
vec2
pos
)
{
charge_t
c
=
{.
q
=
q
,
.
pos
=
pos
};
charge_t
c
=
{.
q
=
q
,
.
pos
=
pos
};
return
c
;
return
c
;
}
double
random_charge_q
(
bool
positive
)
{
return
rand_one
()
*
(
positive
?
1
:
-
1
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
charge/charge.h
+
8
−
0
View file @
5b006cbf
...
@@ -109,4 +109,12 @@ bool compute_p_next(charge_t *charges, int num_charges, double eps,
...
@@ -109,4 +109,12 @@ bool compute_p_next(charge_t *charges, int num_charges, double eps,
*/
*/
charge_t
charge_create
(
double
q
,
vec2
pos
);
charge_t
charge_create
(
double
q
,
vec2
pos
);
/**
* @brief Return a random charge q
*
* @param positive
* @return double
*/
double
random_charge_q
(
bool
positive
);
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.c
+
8
−
3
View file @
5b006cbf
...
@@ -84,13 +84,18 @@ void handle_mouse_input(int button, int state, int x, int y) {
...
@@ -84,13 +84,18 @@ void handle_mouse_input(int button, int state, int x, int y) {
if
(
state
==
GLUT_UP
)
if
(
state
==
GLUT_UP
)
return
;
return
;
if
(
button
==
GLUT_LEFT_BUTTON
)
{
if
(
button
==
GLUT_LEFT_BUTTON
||
button
==
GLUT_RIGHT_BUTTON
)
{
charge_count
+=
1
;
charge_count
+=
1
;
default_charges_pos
[
charge_count
-
1
]
=
default_charges_pos
[
charge_count
-
1
]
=
vec2_create
((
double
)
x
/
WINDOW_WIDTH
,
(
double
)
y
/
WINDOW_HEIGHT
);
vec2_create
((
double
)
x
/
WINDOW_WIDTH
,
(
double
)
y
/
WINDOW_HEIGHT
);
default_charges
[
charge_count
-
1
]
=
rand_one
()
/
(
rand_one
()
*
10
-
5
);
}
}
if
(
button
==
GLUT_LEFT_BUTTON
)
default_charges
[
charge_count
-
1
]
=
random_charge_q
(
true
);
if
(
button
==
GLUT_RIGHT_BUTTON
)
default_charges
[
charge_count
-
1
]
=
random_charge_q
(
false
);
glutPostRedisplay
();
glutPostRedisplay
();
}
}
...
@@ -106,7 +111,7 @@ int main(int argc, char **argv) {
...
@@ -106,7 +111,7 @@ int main(int argc, char **argv) {
// Generate all default charges
// Generate all default charges
for
(
int
i
=
0
;
i
<
charge_count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
charge_count
;
i
++
)
{
default_charges
[
i
]
=
rand
_one
()
/
(
rand_one
()
*
10
-
5
);
default_charges
[
i
]
=
rand
om_charge_q
((
bool
)(
rand
()
%
2
==
0
)
);
default_charges_pos
[
i
]
=
vec2_create
(
rand_one
(),
rand_one
());
default_charges_pos
[
i
]
=
vec2_create
(
rand_one
(),
rand_one
());
}
}
...
...
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