From 43be825bfbba73cc342e0ba096f7d2fffc130ce5 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Fri, 21 Oct 2016 13:07:58 +0200 Subject: [PATCH] Remove init function --- src/main.cpp | 68 ++++++++++++++++++++++++++++++++++----------------- test.tga | Bin 6220818 -> 786450 bytes 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7e16817..423ce31 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,27 +2,6 @@ using namespace std; - bool init(char* inputName, scene &myScene) - { - int nbMat, nbSphere, nbLight; - int i; - ifstream sceneFile(inputName); - if (!sceneFile) - return false; - sceneFile >> myScene.sizex >> myScene.sizey; - sceneFile >> nbMat >> nbSphere >> nbLight; - myScene.matTab.resize(nbMat); - myScene.sphTab.resize(nbSphere); - myScene.lgtTab.resize(nbLight); - for (i=0; i < nbMat; i++) - sceneFile >> myScene.matTab[i]; - for (i=0; i < nbSphere; i++) - sceneFile >> myScene.sphTab[i]; - for (i=0; i < nbLight; i++) - sceneFile >> myScene.lgtTab[i]; - return true; - } - bool hitSphere(const ray &r, const sphere &s, float &t) { // intersection rayon/sphere @@ -151,10 +130,53 @@ using namespace std; return true; } + void addMaterial(scene* s,float r,float g,float b,float reflection){ + material a; + a.red = r; + a.green = g; + a.blue = b; + a.reflection = reflection; + s->matTab.push_back(a); + } + + void addSphere(scene* s,float x,float y,float z,float size,int material){ + sphere sb; + sb.pos.x = x; + sb.pos.y = y; + sb.pos.z = z; + sb.size = size; + sb.material = material; + s->sphTab.push_back(sb); + } + + void addLight(scene* s,float x,float y,float z,float r,float g,float b){ + light la; + la.pos.x = x; + la.pos.y = y; + la.pos.z = z; + la.red = r; + la.green = g; + la.blue = b; + s->lgtTab.push_back(la); + } + int main(int argc, char* argv[]) { scene myScene; - if (!init("scene.txt", myScene)) - return -1; + + myScene.sizex = 512; + myScene.sizey = 512; + + addMaterial(&myScene,1.0,1.0,0.0,0.5); + addMaterial(&myScene,0.0,1.0,1.0,0.5); + addMaterial(&myScene,1.0,0.0,1.0,0.5); + + addSphere(&myScene,233.0,290.0,0.0,100,0); + addSphere(&myScene,407.0,290.0,0.0,100,1); + addSphere(&myScene,320.0,140.0,0.0,100,2); + + addLight(&myScene,0.0,240.0,-100.0,1.0,1.0,1.0); + addLight(&myScene,640.0,240.0,-10000.0,0.6,0.7,1.0); + if (!draw("test.tga", myScene)) return -1; return 0; diff --git a/test.tga b/test.tga index 0ac60072c2c25060f3db7376d0f1bce9ba7527cf..236301586d5cd58a02c6c4de2c493c69e44257bf 100644 GIT binary patch delta 2258 zcmYL~2~bsK7={fvzg+IU=Uy+{WmOPF6hRTvKoK%ER7}kc6HP~xAeYfnb4%25X)H%4 zI^{kp9ExWbcbkF~c*@_kQ2`&wtLGbMDHjS57PEwYN5D z;?(57Kc^;6GV7*2#I~))^xLxSI_FwN{#@!@r%1OG&h?7Sy6XH?kVo7} z2$>e|g5=@=azHwHVlLSu8`RoAauM=K9tXP|V!We@MBJdr0!4v``77|v(e%J%`sz`n zeHxj)jJahKec3M3P)RPjMLIW-^V|j45KhiaBaCRSq{^t=?-lwKGxe9s8?h5T4 z1wGz_+G_-~VhZ(xrO@*A)TABIgD0s8*Ik9a?*-}vs{wUcD}#{nU8y@iHVD0Q2I`&j zSjTFpw-=y}EoWWw2kPiLpromrkkNr|2#aFegdWugC>o70Y6ipn?@>qO0QqIKGqgKs zN4#d+;b|0lcm&{hpO#9SL|a5#L;J-jw5V`Zk%h;MuM|D}3Oj!rg$y^Fu*8;@CZV^A z1Ge<1jW-FoWsb=iNB)4?u@wkEXlh(Tm;I|usaT_y9Tzh?e&)tbfrgGvrbnBT(Ebn| z$4IunLc6G&dPJ)kZ!%~NLsXMCu^t<;EL1(^x@Bfn;ob_g%371Btlel%XsnC1QSPdr zHm5?hXr^i$vwW1^*L|RwvP~9k>jc#-V=B$hUG)5$Z#Goi zxTJ<9ZFtJe;fl<+skkVd4L7(O5H&;ldi;iWYkrTdKKlG05~)YH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