Tutoriel ODE n°05 : Pourquoi pas des ombres ?! « le: 27 Octobre 2005 à 16:54:40 » Pourquoi ne pas rajouter des ombres à nos cube ? Dans le fichier Inc_BlitzODE replacez Code: Type TODEGeom Field body% Field geom% Field mesh% End Type Par Code: Type TODEGeom Field body% Field geom% Field mesh% Field shadow% End Type Ensuite dans ce meme fichier remplacer la fonction : ODE_UpdateGeoms() Par celle-ci Code: Function ODE_UpdateGeoms() For g.TODEGeom = Each TODEGeom PositionEntity gmesh, ODE_dGeomGetPositionX(ggeom), ODE_dGeomGetPositionY(ggeom), ODE_dGeomGetPositionZ(ggeom) RotateEntity gmesh, ODE_dGeomGetPitch(ggeom), ODE_dGeomGetYaw(ggeom), ODE_dGeomGetRoll(ggeom), 1 ; -------------------------------------------------- ; Gestion a deux francs des ombres ; -------------------------------------------------- PositionEntity gshadow, ODE_dGeomGetPositionX(ggeom), 0.05, ODE_dGeomGetPositionZ(ggeom) RotateEntity gshadow, 0,ODE_dGeomGetYaw(ggeom), 0 Next End Function Et voici le programme principal, vous noterez que nous avons corrigé un bug sur les tailles des rigid body ODE => Unité de mesure Blitz Code: ; ------------------------------------------------------ ; Chargement des fichiers necessaires ; ------------------------------------------------------ Include "Inc_BlitzODE.bb" Include "Inc_Camera.bb" Include "Inc_LiGht.bb" ; ----------------------------- ; Ouverture de l'ecran ; ----------------------------- Graphics3D 800, 600,32,2 SetBuffer BackBuffer() ; ---------------------------------------------- ; Initialisation camera et lumières ; ---------------------------------------------- Proc_CreateCamera() Proc_CreateLiGht() ; ---------------------- ; Creation du sol ; ---------------------- Plane = CreatePlane() EntityColor Plane, 100,100, 100 ; ------------------------------ ; Initialisation de ODE ; ------------------------------ Global ODE_Plane = True Global ODE_World = ODE_dWorldCreate(ODE_Plane ) ODE_dSetContactMode(dContactBounce + dContactSoftERP + dContactSoftCFM) ODE_dSetBOUNCE(0.1) ODE_dSetSOFT_ERP(1.5) ; Essayez 6.5 pour avoir un sol super rebondissant ODE_dSetSOFT_CFM(0.1) ; Essayez 3.2 pour rendre le sol moue (pour des effets d'eau par exemple) ; ----------------------------------------- ; Creation de plusieurs cubes ; ----------------------------------------- ZoneDiffusion=35 For I=1 To 80 Proc_CreateODECube(Rnd(-ZoneDiffusion,ZoneDiffusion),20,Rnd(-ZoneDiffusion,ZoneDiffusion),45,45,45,2,2,2,Rnd(1,15),Rnd(255),Rnd(255),Rnd(255)) Next ; ------------------------- ; Boucle principale ; ------------------------- While Not KeyHit(1) ; ------------------------------------------------- ; Rafraichissement du monde ODE ; ------------------------------------------------- ODE_dWorldQuickStep 0.1 ODE_UpdateGeoms() ; -------------------------------------------------------------------------------------------------------------------------------------------------- ; Cliquez lentement sur la souris pour appliquer une force aleatoire vers le haut ! devinez pour X et Z .... ; -------------------------------------------------------------------------------------------------------------------------------------------------- If MouseHit(1) Then Proc_AddForce(0,Rnd(80,200),0) EndIf UpdateWorld RenderWorld ; ------------------------ ; Camera freelook ; ------------------------ Proc_Freelook(Camera_Ent,1.2,0.05) Flip Wend ODE_dCloseODE() End ; -------------------------------------------- ; Permet de créer un cube ODE ; -------------------------------------------- Function Proc_CreateODECube(Px#,Py#,Pz#,Rx#,Ry#,Rz#,Sx#,Sy#,Sz#,Mass#,Red,Green,Blue) G.TODEGeom = New TODEGeom GBody = ODE_dBodyCreate() ; ---------------------------------------------------------------------------------------------------------- ; Pour une raison obsur vous devez multiplier par x 2 la taille de votre ; RIGID BODY pour etre callé correctement avec les unités de mesure blitz ; ---------------------------------------------------------------------------------------------------------- GGeom = ODE_dCreateBox(ODE_World,Sx#*2,Sy#*2,Sz#*2,Mass#) ODE_dGeomSetBody GGeom, Gbody ODE_dBodySetPosition(Gbody, Px#,Py#,Pz#) ODE_dBodySetRotation(Gbody, Rx#,Ry#,Rz#) GMesh = CreateCube() EntityColor Gmesh, Red,Green,Blue EntityShininess Gmesh, 0.7 ScaleEntity GMesh , Sx#,Sy#,Sz# GShadow = CreateCube() EntityColor GShadow , 0,0,0 EntityAlpha GShadow , 0.3 ScaleEntity GShadow , Sx#,0.01,Sz# ODE_UpdateGeoms() End Function ; -------------------------------------------------------------------------- ; Applique une force sur tout les objets RIGID BODY ; -------------------------------------------------------------------------- Function Proc_AddForce(Fx#,Fy#,Fz#) For g.TODEGeom = Each TODEGeom ODE_dBodyAddForce(Gbody, Fx#,Fy#,Fz#) Next End Function Journalisée "Je crois au moment. S'il n'y a pas le moment, à ce moment-là, il faut arriver à ce moment-là, au moment qu'on veut." JC Vandamme "En 1 semaine, t'as réussit à pourrir quasiment tous les topics et en déterrer des tellement vieux, que même un nécrophile y mettrait pas sa bite." Wako bobysait Administrator Floodeur ***** Karma: 43 Messages: 4034 M.Kobayashi? WWW Re : Tutoriel ODE n°05 : Pourquoi pas des ombres ?! « Répondre #1 le: 23 Mai 2007 à 03:07:32 » ptite suggestion "à 2 balles" aussi :grin: remplace : Code: ; -------------------------------------------------- ; Gestion a deux francs des ombres ; -------------------------------------------------- PositionEntity gshadow, ODE_dGeomGetPositionX(ggeom), 0.05, ODE_dGeomGetPositionZ(ggeom) RotateEntity gshadow, 0,ODE_dGeomGetYaw(ggeom), 0 par Code: ; -------------------------------------------------- ; Gestion a deux francs des ombres ; -------------------------------------------------- If gshadow PositionEntity gshadow, ODE_dGeomGetPositionX(ggeom), 0.05, ODE_dGeomGetPositionZ(ggeom) RotateEntity gshadow, 0,ODE_dGeomGetYaw(ggeom), 0 EndIf histoire de conserver la compatibilité des anciennes demos avec le nouveau code