Commit c1630526 authored by DUVAL LOUIS's avatar DUVAL LOUIS
Browse files

Merge branch 'master' into 'main'

Master

See merge request !1
parents 437e9164 39e3173e
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${default}",
"/usr/include/SDL2"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
\ No newline at end of file
{
// Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
// Pointez pour afficher la description des attributs existants.
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc-9 - Générer et déboguer le fichier actif",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc-9 générer le fichier actif",
"miDebuggerPath": "/bin/gdb"
}
]
}
\ No newline at end of file
{
"files.associations": {
"*.tcc": "c",
"algorithm": "c",
"iterator": "c",
"memory": "c",
"random": "c",
"functional": "c",
"cmath": "c",
"stdlib.h": "c"
}
}
\ No newline at end of file
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc-9 générer le fichier actif",
"command": "/usr/bin/gcc-9",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Tâche générée par le débogueur."
}
],
"version": "2.0.0"
}
\ No newline at end of file
LDLIBS=-ltps -lSDL2 -lSDL2_ttf -lm
compile: main.c
echo "comiling ..."
gcc main.c -o main -g $(LDLIBS)
exec: main
echo "executing ..."
./main
clean:
echo "cleaning ..."
rm main
run: compile exec clean
echo finish ...
compilewarning:
echo "compWARN ..."
gcc main.c -o main -g $(LDLIBS) -Wall -Wextra
debug: compilewarning exec clean
echo finishW...
\ No newline at end of file
#include <stdio.h>
#include <tps.h>
#include <math.h>
typedef struct Point {
int x, y;
}Point;
typedef struct Rond{
int radius;
bool fill;
Point centre;
}Rond;
void printpoint(Point monpoint){
printf("==Point==\nx=%d\ny=%d\n",monpoint.x,monpoint.y);
}
void cleanclickront(Rond *liste,int size){
if(tps_getMouseButtons() & SDL_BUTTON(SDL_BUTTON_LEFT) ){
for(int u = 0; u < size; u++){
liste[u].centre.y=0;liste[u].centre.x=0;
liste[u].radius=5;
}
}
}
Point cliqueCoord() {
// if(! tps_getMouseButtons() & SDL_BUTTON(SDL_MOUSEBUTTONUP)){
tps_wait(100);
if(tps_getMouseButtons() & SDL_BUTTON(SDL_BUTTON_RIGHT) ){
int x,y;
x=y=0;
tps_getMousePosition(&x, &y);
x=10;y=90;
Point ptsTemporaire = { .x = x, .y = y};
return ptsTemporaire;
// }
}
}
void renderlist(Rond *liste,int longeur){
int i=0;
for(int i = 0; i < longeur;i++)
{
if( liste[i].centre.x == 0 && liste[i].centre.y == 0 ){
return;
}
tps_fillEllipse(liste[i].centre.x, liste[i].centre.y,liste[i].radius , liste[i].radius);
}
}
int addpoint(Point *liste,int longeur){
int i=0;
for(int i = 0; i < longeur;i++)
{
if( liste[i].x == 0 && liste[i].x == 0 ){
liste[i] = cliqueCoord();
return i;
}
}
}
int distance(Point a,Point b){
printf("%f",sqrt(((a.x-b.x)*(a.x-b.x))+(a.y-b.y)*(a.y-b.y)));
return 30; //sqrt((b.x-b.y)*(b.x-b.y)); //sqrt(((a.x-b.x)*(a.x-b.x))+(a.y-b.y)*(a.y-b.y));
}
void addRond(Rond *listedesrond,int tailleliste){
int decalage = addpoint(&listedesrond->centre,tailleliste);
Point segondclique = cliqueCoord();
listedesrond[decalage].radius=distance(listedesrond[decalage].centre,segondclique);
}
int main(void) {
tps_wait(100);
tps_createWindow("Fenètre1", 800, 600);
int x,y;
x=y=0;
int longeur=20;
Rond listrond[20]={0};
listrond[0].centre.x = 1;
listrond[0].centre.y = 1;
while(tps_isRunning()) {
tps_drawFPS();
tps_background(255,255,255);
tps_setColor(0,0,0);
addRond(listrond,longeur);
renderlist(listrond,longeur);
cleanclickront(listrond,longeur);
tps_render();
}
tps_closeWindow();
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <tps.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
typedef struct Point {
float x, y;
}Point;
typedef struct Segment {
Point A,B;
}Segment;
typedef struct Eye {
Point centre;
float range;
float precision;
}Eye;
void rstcolor(){
tps_setColor(0,0,0);
}
void color(char c){
switch (c)
{
case 'r':
tps_setColor(255,0,0);
break;
case 'v':
tps_setColor(0,255,0);
break;
case 'b':
tps_setColor(0,0,255);
break;
default:
tps_setColor(0,0,0);
break;
}
}
void ptstest(Point point, char c){
color(c);
tps_fillEllipse(point.x,point.y,10,10);
rstcolor();
}
Point pscal(Point A,Point B){
Point resultat = {(A.x*B.x),A.y*B.y};
return resultat;
}
Point psum(Point A, Point B){
Point out = {B.x-A.x, B.y-A.y};
return out;
}
Point padd(Point A, Point B){
Point out = {B.x+A.x, B.y+A.y};
return out;
}
bool pcompegal(Point A, Point B){
if(A.x == B.x && A.y == B.y){
return true;
}
return false;
}
void placeSegment(Segment mure){
tps_drawLine(mure.A.x,mure.A.y,mure.B.x,mure.B.y);
}
void placeListeSegment(Segment *liste,int taille){
for(int u =0 ; u < taille; u++){
placeSegment(liste[u]);
}
}
float norme(Point A, Point B){
return sqrt(pow(B.x-A.x,2)+pow(B.y-A.y,2));
}
Point intersect(Segment A, Segment B){
// printf("\n++++++++++++++\nx1=%f,y1=%f\nx2=%f,y2=%f\nx3=%f,y3=%f\nx4=%f,y4=%f\n",A.A.x,A.A.y,A.B.x,A.B.y,B.A.x,B.A.y,B.B.x,B.B.y);
//utiliser les multiplication est soustraction de point dirrectemetn
float s1=A.B.x-A.A.x;
float t1=B.B.x-B.A.x;
float s2=A.B.y-A.A.y;
float t2=B.B.y-B.A.y;
float r1=B.A.x-A.A.x;
float r2=B.A.y-A.A.y;
// s1-t1 == r1;
// s2-t2 == r2;
Point null = {0,0};
if(s1*t2-s2*t1 == 0){
return null;
}
// printf("\n==============\nr1=%f\nr2=%f\ns1=%f\ns2=%f\nt1=%f\nt2=%f\n",r1,r2,s1,s2,t1,t2);
float s = (r1*t2-r2*t1)/(s1*t2-s2*t1);
float t = (s1*r2-s2*r1)/(s1*t2-s2*t1);
if (s > 1 || s < 0){
return null;
}
if (-t > 1 || -t < 0){
return null;
}
// printf("s=%f\nt=%f",s,t);
float x = A.A.x+s*(A.B.x-A.A.x);
float y = A.A.y+s*(A.B.y-A.A.y);
Point rep = {x,y};
return rep;
}
void scan(Eye lanceur, Segment *object,int taille){
for(float i =0;i<2*3.14159265359;i+=lanceur.precision){
//calcule les coordoner des point pour le cercle
Point pCercleExterieur = {lanceur.centre.x+lanceur.range*cos(i)
, lanceur.centre.y+lanceur.range*sin(i)};
Segment rayon = {pCercleExterieur,lanceur.centre};
//lol on testera tout les objet le la map LA FAMEUSE OPTIMISATION
for(int u = 0; u<taille;u++){
Point touche = intersect(rayon,object[u]);
//wtf ces censer etre l'inverse ...
if( touche.x != 0 && touche.y != 0 ){
//on verifie que lobjet qui a toucher est bien plus proche que le precedant
rayon.A = touche; //si oui allor le pron rayon lancer sera plus cour ect
}
}
//on verifie si le rayon a toucher un truc au final
if(!pcompegal(rayon.A,pCercleExterieur)){
ptstest(rayon.A,'r');//si oui alor on fait le boom
}
placeSegment(rayon);
tps_render();
tps_wait(5);
}
}
void benchmark(){
Segment test = {{rand()%600,rand()%600},{rand()%600,rand()%600}};
Segment test2 = {{rand()%600,rand()%600},{rand()%600,rand()%600}};
if(intersect(test,test2).x != 0 && intersect(test,test2).y !=0){
tps_background(255,255,255);
ptstest(intersect(test,test2),'v');
}else{
tps_background(200,150,255);
ptstest(intersect(test,test2),'r');
}
placeSegment(test);
placeSegment(test2);
tps_render();
}
void initrandomlisteobject(Segment *trairandom, int taille){
for(int i=0; i<taille;i++){
Segment monsegement ={{rand()%800,rand()%600},{rand()%800,rand()%600}};
trairandom[i] = monsegement;
}
}
int main(void) {
static int nombreDeMure=5;
srand(time(NULL));
tps_createWindow("Fenètre1", 800, 600);
Eye millieux = {{400,300}, 300, 0.02};
// printf("%d,%d",x,y);
while(tps_isRunning()) {
tps_background(255,255,255);
tps_setColor(0,0,0);
//on genere des "mure" random
Segment trairandom[nombreDeMure];
initrandomlisteobject(trairandom,nombreDeMure);
//on place une liste de segement pour l'affichage
placeListeSegment(trairandom,nombreDeMure);
scan(millieux,trairandom,nombreDeMure);
tps_render();
tps_wait(300);
// scan(centre,test);
}
tps_closeWindow();
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment