Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetWorld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LAIRD Timothy
NetWorld
Commits
d606d893
Commit
d606d893
authored
Apr 12, 2021
by
ewen.madec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gabriel Graph generation
parent
8b397725
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
17 deletions
+77
-17
main-viewer.c
src/main-viewer.c
+13
-2
networld.c
src/networld.c
+4
-3
networld.h
src/networld.h
+4
-1
randomMap.c
src/randomMap.c
+51
-10
randomMap.h
src/randomMap.h
+5
-1
No files found.
src/main-viewer.c
View file @
d606d893
...
@@ -28,10 +28,18 @@ bool game_end;
...
@@ -28,10 +28,18 @@ bool game_end;
int
main
(
int
nbArg
,
char
**
arg
)
int
main
(
int
nbArg
,
char
**
arg
)
{
{
int
n
=
10
;
int
n
=
5
;
NetWorld
*
world
=
NetWorld_new
(
n
);
NetWorld
*
world
=
NetWorld_new
(
n
);
world
=
Random_map
(
world
,
n
);
world
=
Random_map
(
world
,
n
);
//Node_set(&(world->nodes[0]), (Vector2){1.4f, 1.28f}, ORANGE);
printf
(
"positionX %f
\n
"
,
world
->
nodes
[
0
].
position
.
x
);
printf
(
"positionY %f
\n
"
,
world
->
nodes
[
0
].
position
.
y
);
printf
(
"positionX %f
\n
"
,
world
->
nodes
[
1
].
position
.
x
);
printf
(
"positionY %f
\n
"
,
world
->
nodes
[
1
].
position
.
y
);
printf
(
"distXY %f
\n
"
,
dist
(
world
->
nodes
[
0
],
world
->
nodes
[
1
]));
// Game Initialization
// Game Initialization
//--------------------
//--------------------
...
@@ -50,8 +58,10 @@ int main(int nbArg, char ** arg)
...
@@ -50,8 +58,10 @@ int main(int nbArg, char ** arg)
InitWindow
(
screenWidth
,
screenHeight
,
"NetWorld basic viewer"
);
InitWindow
(
screenWidth
,
screenHeight
,
"NetWorld basic viewer"
);
SetTargetFPS
(
targetFPS
);
SetTargetFPS
(
targetFPS
);
// Some verificcations
// Some verificcations
//--------------------
//--------------------
/*
puts("world variable:");
puts("world variable:");
NetWorld_print(world);
NetWorld_print(world);
puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]");
puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]");
...
@@ -59,6 +69,7 @@ int main(int nbArg, char ** arg)
...
@@ -59,6 +69,7 @@ int main(int nbArg, char ** arg)
Vector2 position= {1.f, 1.f};
Vector2 position= {1.f, 1.f};
position= Panel_pixelFromPosition( panel, &position );
position= Panel_pixelFromPosition( panel, &position );
printf("[%.2f,%.2f]\n", position.x, position.y);
printf("[%.2f,%.2f]\n", position.x, position.y);
*/
// Main game loop
// Main game loop
while
(
!
game_end
&&
!
WindowShouldClose
())
// Detect window close button or ESC key
while
(
!
game_end
&&
!
WindowShouldClose
())
// Detect window close button or ESC key
...
...
src/networld.c
View file @
d606d893
...
@@ -12,12 +12,12 @@
...
@@ -12,12 +12,12 @@
// Constructor / Destructor
// Constructor / Destructor
void
Node_construct
(
Node
*
self
)
void
Node_construct
(
Node
*
self
)
{
{
Node_set
(
self
,
(
Vector2
){
0
.
f
,
0
.
f
},
GRAY
);
Node_set
(
self
,
(
Vector2
){
0
.
f
,
0
.
f
},
GRAY
,
""
);
self
->
card
=
0
;
self
->
card
=
0
;
self
->
edges
=
Edge_newArray
(
0
);
self
->
edges
=
Edge_newArray
(
0
);
self
->
name
=
malloc
(
sizeof
(
char
)
*
32
);
self
->
name
=
malloc
(
sizeof
(
char
)
*
32
);
self
->
continent
=
malloc
(
sizeof
(
char
)
*
32
);
self
->
continent
=
malloc
(
sizeof
(
char
)
*
32
);
self
->
soldiers
=
1
;
self
->
soldiers
=
5
;
strcpy
(
self
->
continent
,
"None"
);
strcpy
(
self
->
continent
,
"None"
);
strcpy
(
self
->
name
,
"Node"
);
strcpy
(
self
->
name
,
"Node"
);
}
}
...
@@ -85,10 +85,11 @@ void Node_resize( Node * self, int card )
...
@@ -85,10 +85,11 @@ void Node_resize( Node * self, int card )
self
->
card
=
card
;
self
->
card
=
card
;
}
}
void
Node_set
(
Node
*
self
,
Vector2
position
,
Color
color
)
void
Node_set
(
Node
*
self
,
Vector2
position
,
Color
color
,
char
*
name
)
{
{
self
->
position
=
position
;
self
->
position
=
position
;
self
->
color
=
color
;
self
->
color
=
color
;
self
->
name
=
name
;
}
}
int
Node_connect
(
Node
*
self
,
Node
*
target
)
int
Node_connect
(
Node
*
self
,
Node
*
target
)
...
...
src/networld.h
View file @
d606d893
...
@@ -108,7 +108,10 @@ void Node_set(
...
@@ -108,7 +108,10 @@ void Node_set(
//! position
//! position
Vector2
position
,
Vector2
position
,
//! color
//! color
Color
color
Color
color
,
//!
char
*
name
);
);
/**
/**
...
...
src/randomMap.c
View file @
d606d893
...
@@ -11,27 +11,68 @@
...
@@ -11,27 +11,68 @@
#include "raylib.h"
#include "raylib.h"
double
randfrom
(
double
min
,
double
max
)
{
double
range
=
(
max
-
min
);
double
div
=
RAND_MAX
/
range
;
return
min
+
(
rand
()
/
div
);
}
double
dist
(
Node
node1
,
Node
node2
){
return
(
sqrt
(
(
node2
.
position
.
x
-
node1
.
position
.
x
)
*
(
node2
.
position
.
x
-
node1
.
position
.
x
)
+
(
node2
.
position
.
y
-
node1
.
position
.
y
)
*
(
node2
.
position
.
y
-
node1
.
position
.
y
)
));
}
NetWorld
*
Random_map
(
NetWorld
*
world
,
int
nbNode
)
NetWorld
*
Random_map
(
NetWorld
*
world
,
int
nbNode
)
{
{
int
i
;
int
i
;
float
randomX
,
randomY
;
float
randomX
,
randomY
;
/* Intializes random number generator */
/* Intializes random number generator */
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
/* Print 5 random numbers from 0 to 15.00 */
/* Print 5 random numbers from
-15.0
0 to 15.00 */
for
(
i
=
0
;
i
<
nbNode
;
i
++
)
{
for
(
i
=
0
;
i
<
nbNode
;
i
++
)
{
randomX
=
(
rand
()
%
1500
)
/
100
.
0
;
double
randomX
=
randfrom
(
-
15
.
0
,
15
.
0
);
randomY
=
(
rand
()
%
1500
)
/
100
.
0
;
double
randomY
=
randfrom
(
-
15
.
0
,
15
.
0
);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
);
char
*
name
;
printf
(
"%f
\n
bNode"
,
randomX
);
name
=
malloc
(
sizeof
(
int
));
printf
(
"%f
\n
bNode"
,
randomY
);
sprintf
(
name
,
"name : %d"
,
i
);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
,
name
);
printf
(
"%f
\n
"
,
randomX
);
printf
(
"%f
\n
"
,
randomY
);
if
(
i
!=
nbNode
-
1
){
/*
if(i!= nbNode-1){
NetWorld_connect(world, i, i+1);
NetWorld_connect(world, i, i+1);
}
}
else{
else{
NetWorld_connect(world, i, 0);
NetWorld_connect(world, i, 0);
}
}
*/
}
}
//Gabriel graph sort
for
(
int
i
=
0
;
i
<
nbNode
-
1
;
i
++
){
for
(
int
j
=
i
+
1
;
j
<
nbNode
;
j
++
){
int
compteurPointDansLeCercle
=
0
;
float
xm
=
0
.
5
*
(
world
->
nodes
[
i
].
position
.
x
+
world
->
nodes
[
j
].
position
.
x
);
float
ym
=
0
.
5
*
(
world
->
nodes
[
i
].
position
.
y
+
world
->
nodes
[
j
].
position
.
y
);
float
distCenterOfij
=
sqrt
((
xm
-
world
->
nodes
[
i
].
position
.
x
)
*
(
xm
-
world
->
nodes
[
i
].
position
.
x
)
+
(
ym
-
world
->
nodes
[
i
].
position
.
y
)
*
(
ym
-
world
->
nodes
[
i
].
position
.
y
));
printf
(
"xm : %f
\n
"
,
xm
);
printf
(
"ym : %f
\n
"
,
ym
);
printf
(
"distCenterOfij : %f
\n
"
,
distCenterOfij
);
printf
(
"dist %d%d : %f
\n
"
,
i
,
j
,
dist
((
world
->
nodes
[
i
]),
world
->
nodes
[
j
]));
//printf("dist sqrt : %f\n", sqrt(dist((world->nodes[i]),world->nodes[p])*dist((world->nodes[i]),world->nodes[p]) + dist((world->nodes[j]),world->nodes[p])*dist((world->nodes[j]),world->nodes[p])));
for
(
int
k
=
0
;
k
<
nbNode
;
k
++
){
/* if((xm - distCenterOfij < world->nodes[k].position.x < xm + distCenterOfij) && (ym - distCenterOfij < world->nodes[k].position.y < ym + distCenterOfij) ){
compteurPointDansLeCercle ++;
} */
printf
(
" dist center - Node k %f
\n
"
,
sqrt
((
world
->
nodes
[
k
].
position
.
x
-
xm
)
*
(
world
->
nodes
[
k
].
position
.
x
-
xm
)
+
(
world
->
nodes
[
k
].
position
.
y
-
ym
)
*
(
world
->
nodes
[
k
].
position
.
y
-
ym
)));
if
(
sqrt
((
world
->
nodes
[
k
].
position
.
x
-
xm
)
*
(
world
->
nodes
[
k
].
position
.
x
-
xm
)
+
(
world
->
nodes
[
k
].
position
.
y
-
ym
)
*
(
world
->
nodes
[
k
].
position
.
y
-
ym
))
<
distCenterOfij
-
0
.
05
){
compteurPointDansLeCercle
++
;
}
}
printf
(
"compteurPointDansLeCercle : %i
\n
"
,
compteurPointDansLeCercle
);
if
(
compteurPointDansLeCercle
==
0
){
NetWorld_connect
(
world
,
i
,
j
);
}
}
}
return
world
;
return
world
;
}
}
\ No newline at end of file
src/randomMap.h
View file @
d606d893
...
@@ -2,4 +2,8 @@
...
@@ -2,4 +2,8 @@
#include "networld.h"
#include "networld.h"
NetWorld
*
Random_map
(
NetWorld
*
world
,
int
nbNode
);
NetWorld
*
Random_map
(
NetWorld
*
world
,
int
nbNode
);
\ No newline at end of file
double
randfrom
(
double
min
,
double
max
);
double
dist
(
Node
node1
,
Node
node2
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment