texte initial | correction | date |
---|---|---|
Bonjour a tous. |
Bonjour a tous.
|
25-10-2010 23:34:46 |
ben je vient de faire t'es modification mais quand je monte et que je tourne a droite ou a gauche il fait une boucle bizard qui n'est pas bon voila le code que j'ai fait Code:#include <irrlicht.h>
#include "CShieldManager.h"
#include "Following_Camera.h"
#include "CEventManager.h"
using namespace irr;
using namespace core;
using namespace gui;
using namespace video;
using namespace scene;
void event_manager(MyEventReceiver *receiver, IAnimatedMeshSceneNode *battle_turtle1, ISceneNode* plane)
{
int rot1 = 0, rot2 = 0;
vector3df rot, rrot;
rot.Y += 0.7;
if(receiver->IsKeyDown(KEY_KEY_Z))
{
vector3df facing(cos(battle_turtle1->getRotation().Y * PI/180.0f), -sin(battle_turtle1->getRotation().Z * PI/180.0f), -sin(battle_turtle1->getRotation().Y * PI/180.0f));
facing.normalize();
vector3df newPos = battle_turtle1->getPosition() - (facing + (facing * (f32)0.5f));
battle_turtle1->setPosition(newPos);
if(receiver->IsKeyDown(KEY_KEY_Q))
{
if (battle_turtle1->getRotation().X <= -30)
{
rot1 = 0;
}
else
{
rot1 = rot1 + 1;
}
battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(-rot1,-rot.Y,0));
}
else if(receiver->IsKeyDown(KEY_KEY_D))
{
if (battle_turtle1->getRotation().X >= 30)
{
rot2 = 0;
}
else
{
rot2 = rot2 + 1;
}
battle_turtle1->setRotation(battle_turtle1->getRotation()+ vector3df(rot2,rot.Y,0));
}
else if(receiver->IsKeyDown(KEY_KEY_Q) == false && receiver->IsKeyDown(KEY_KEY_D) == false)
{
if (battle_turtle1->getRotation().X < 0)
{
rot1 = rot1 + 1;
}
else if (battle_turtle1->getRotation().X == 0)
{
rot1 = 0;
rot2 = 0;
}
else if (battle_turtle1->getRotation().X > 0)
{
rot2 = rot2 - 1;
}
battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot1,0,0));
battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot2,0,0));
}
}
else if(receiver->IsKeyDown(KEY_KEY_Q))
{
if (battle_turtle1->getRotation().X <= -30)
{
rot1 = 0;
}
else
{
rot1 = rot1 + 1;
}
battle_turtle1->setRotation(battle_turtle1->getRotation()+vector3df(-rot1,-rot.Y,0));
}
else if(receiver->IsKeyDown(KEY_KEY_A))
{
battle_turtle1->setRotation(battle_turtle1->getRotation()+vector3df(0,0,1));
}
else if(receiver->IsKeyDown(KEY_KEY_E))
{
battle_turtle1->setRotation(battle_turtle1->getRotation()-vector3df(0,0,1));
}
else if(receiver->IsKeyDown(KEY_KEY_D))
{
if (battle_turtle1->getRotation().X >= 30)
{
rot2 = 0;
}
else
{
rot2 = rot2 + 1;
}
battle_turtle1->setRotation(battle_turtle1->getRotation()+ vector3df(rot2,rot.Y,0));
}
else if(receiver->IsKeyDown(KEY_KEY_Q) == false && receiver->IsKeyDown(KEY_KEY_D) == false)
{
if (battle_turtle1->getRotation().X < 0)
{
rot1 = rot1 + 1;
}
else if (battle_turtle1->getRotation().X == 0)
{
rot1 = 0;
rot2 = 0;
}
else if (battle_turtle1->getRotation().X > 0)
{
rot2 = rot2 - 1;
}
battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot1,0,0));
battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot2,0,0));
}
}
int main(void)
{
IrrlichtDevice* device = irr::createDevice(EDT_OPENGL,dimension2d<irr::u32>(1024,768),32,false,false,true);
IVideoDriver* driver = device->getVideoDriver ();
ISceneManager *sceneManager = device->getSceneManager ();
scene::IAnimatedMeshSceneNode *shield_node;
sceneManager->addSkyBoxSceneNode(
driver->getTexture("Data/skybox/irrlicht2_up.jpg"),
driver->getTexture("Data/skybox/irrlicht2_dn.jpg"),
driver->getTexture("Data/skybox/irrlicht2_lf.jpg"),
driver->getTexture("Data/skybox/irrlicht2_rt.jpg"),
driver->getTexture("Data/skybox/irrlicht2_ft.jpg"),
driver->getTexture("Data/skybox/irrlicht2_bk.jpg"));
scene::ILightSceneNode* lumiere = sceneManager->addLightSceneNode(0,vector3df(500000,0,10000),SColorf(255, 255, 255),5000000.0f);
lumiere->getLightData().Type = ELT_POINT;
f32 radius = 0.1;
u32 duration = 500;
video::SColorf impact_color(1,1,1,1);
device->getCursorControl ()-> setVisible (true); // curseur invisible
scene::IMeshManipulator *manipulator = sceneManager->getMeshManipulator();
CShieldManager *shieldmanager = new CShieldManager(sceneManager,device->getTimer());
scene::ISceneNode * plane = sceneManager->addCubeSceneNode(0.0001f);
scene::IAnimatedMeshSceneNode *battle_turtle1 = sceneManager->addAnimatedMeshSceneNode(sceneManager->getMesh("Data/model/dedale/dedale.b3d"), plane);
scene::ISceneNode * planet = sceneManager->addSphereSceneNode(5,96);
scene::ISceneNode * soleil = sceneManager->addSphereSceneNode(5,96);
planet->setScale(vector3df(20,20,20));
planet->setPosition(vector3df(20000,0,0));
soleil->setScale(vector3df(20*18,20*18,20*18));
soleil->setPosition(vector3df(0,0,0));
soleil->setMaterialFlag(EMF_LIGHTING, false);
lumiere->setPosition(soleil->getPosition());
battle_turtle1->setScale(core::vector3df(1,1,1));
battle_turtle1->setPosition(core::vector3df(20000,0,100));
battle_turtle1->setMaterialFlag(EMF_LIGHTING, true);
shield_node = sceneManager->addAnimatedMeshSceneNode(sceneManager->getMesh("Data/model/dedale/shield_dedale.b3d"),battle_turtle1);
shield_node->setMaterialTexture(0,driver->getTexture("Data/textures/water.jpg"));
shield_node->setMaterialTexture(1,driver->getTexture("Data/textures/gradient_blinds.png"));
planet->setMaterialTexture(0,driver->getTexture("Data/textures/terre.jpg"));
soleil->setMaterialTexture(0,driver->getTexture("Data/textures/soleil.png"));
manipulator->scaleTCoords(shield_node->getMesh(),core::vector2df(6,6),1);
shield_node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,false);
shield_node->setScale(core::vector3df(1,1,1));
shield_node->setVisible(false);
scene::ITriangleSelector *selector = sceneManager->createTriangleSelector(shield_node->getMesh(),shield_node);
selector = sceneManager->createTriangleSelector(shield_node->getMesh(),shield_node);
shield_node->setTriangleSelector(selector);
selector->drop();
scene::ITriangleSelector *selector1;
shieldmanager->addShield(shield_node);
FollowingCamera* MaCamera = new FollowingCamera(battle_turtle1, sceneManager,false, 50000,selector1,-3,0.5f,0,vector3df(7,2,0)); // Position initiale.
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
int lastFPS = -1;
u32 lastMS = device->getTimer()->getRealTime();
while (device->run()) // la boucle de rendu
{
u32 difMs = device->getTimer()->getRealTime()-lastMS;
lastMS = device->getTimer()->getRealTime();
f32 alignSpeed = difMs/16.0;
if(lastMS%(rand()%20+30)==0)
{
core::vector3df source = vector3df(50,10,50);
core::vector3df target = battle_turtle1->getPosition();
const core::line3df ray(source,target);
core::vector3df result = shieldmanager->addImpact(shield_node, ray,radius*250,duration,impact_color);
core::matrix4 trans = shield_node->getAbsoluteTransformation();
trans.makeInverse();
trans.transformVect(result);
}
event_manager(&receiver,battle_turtle1,plane );
driver->beginScene(true,true,SColor(0,200,200,200));
MaCamera->Update();
sceneManager->drawAll ();
shieldmanager->drawAll();
driver->endScene ();
}
device->drop ();
delete shieldmanager;
delete MaCamera;
return 0;
} |
ben je viens de faire tes modifications mais quand je monte et que je tourne à droite ou à gauche il fait une boucle bizarre qui n'est pas bon voilà le code que j'ai fait
Code:#include <irrlicht.h> #include "CShieldManager.h" #include "Following_Camera.h" #include "CEventManager.h" using namespace irr; using namespace core; using namespace gui; using namespace video; using namespace scene; void event_manager(MyEventReceiver *receiver, IAnimatedMeshSceneNode *battle_turtle1, ISceneNode* plane) { int rot1 = 0, rot2 = 0; vector3df rot, rrot; rot.Y += 0.7; if(receiver->IsKeyDown(KEY_KEY_Z)) { vector3df facing(cos(battle_turtle1->getRotation().Y * PI/180.0f), -sin(battle_turtle1->getRotation().Z * PI/180.0f), -sin(battle_turtle1->getRotation().Y * PI/180.0f)); facing.normalize(); vector3df newPos = battle_turtle1->getPosition() - (facing + (facing * (f32)0.5f)); battle_turtle1->setPosition(newPos); if(receiver->IsKeyDown(KEY_KEY_Q)) { if (battle_turtle1->getRotation().X <= -30) { rot1 = 0; } else { rot1 = rot1 + 1; } battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(-rot1,-rot.Y,0)); } else if(receiver->IsKeyDown(KEY_KEY_D)) { if (battle_turtle1->getRotation().X >= 30) { rot2 = 0; } else { rot2 = rot2 + 1; } battle_turtle1->setRotation(battle_turtle1->getRotation()+ vector3df(rot2,rot.Y,0)); } else if(receiver->IsKeyDown(KEY_KEY_Q) == false && receiver->IsKeyDown(KEY_KEY_D) == false) { if (battle_turtle1->getRotation().X < 0) { rot1 = rot1 + 1; } else if (battle_turtle1->getRotation().X == 0) { rot1 = 0; rot2 = 0; } else if (battle_turtle1->getRotation().X > 0) { rot2 = rot2 - 1; } battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot1,0,0)); battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot2,0,0)); } } else if(receiver->IsKeyDown(KEY_KEY_Q)) { if (battle_turtle1->getRotation().X <= -30) { rot1 = 0; } else { rot1 = rot1 + 1; } battle_turtle1->setRotation(battle_turtle1->getRotation()+vector3df(-rot1,-rot.Y,0)); } else if(receiver->IsKeyDown(KEY_KEY_A)) { battle_turtle1->setRotation(battle_turtle1->getRotation()+vector3df(0,0,1)); } else if(receiver->IsKeyDown(KEY_KEY_E)) { battle_turtle1->setRotation(battle_turtle1->getRotation()-vector3df(0,0,1)); } else if(receiver->IsKeyDown(KEY_KEY_D)) { if (battle_turtle1->getRotation().X >= 30) { rot2 = 0; } else { rot2 = rot2 + 1; } battle_turtle1->setRotation(battle_turtle1->getRotation()+ vector3df(rot2,rot.Y,0)); } else if(receiver->IsKeyDown(KEY_KEY_Q) == false && receiver->IsKeyDown(KEY_KEY_D) == false) { if (battle_turtle1->getRotation().X < 0) { rot1 = rot1 + 1; } else if (battle_turtle1->getRotation().X == 0) { rot1 = 0; rot2 = 0; } else if (battle_turtle1->getRotation().X > 0) { rot2 = rot2 - 1; } battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot1,0,0)); battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot2,0,0)); } } int main(void) { IrrlichtDevice* device = irr::createDevice(EDT_OPENGL,dimension2d<irr::u32>(1024,768),32,false,false,true); IVideoDriver* driver = device->getVideoDriver (); ISceneManager *sceneManager = device->getSceneManager (); scene::IAnimatedMeshSceneNode *shield_node; sceneManager->addSkyBoxSceneNode( driver->getTexture("Data/skybox/irrlicht2_up.jpg"), driver->getTexture("Data/skybox/irrlicht2_dn.jpg"), driver->getTexture("Data/skybox/irrlicht2_lf.jpg"), driver->getTexture("Data/skybox/irrlicht2_rt.jpg"), driver->getTexture("Data/skybox/irrlicht2_ft.jpg"), driver->getTexture("Data/skybox/irrlicht2_bk.jpg")); scene::ILightSceneNode* lumiere = sceneManager->addLightSceneNode(0,vector3df(500000,0,10000),SColorf(255, 255, 255),5000000.0f); lumiere->getLightData().Type = ELT_POINT; f32 radius = 0.1; u32 duration = 500; video::SColorf impact_color(1,1,1,1); device->getCursorControl ()-> setVisible (true); // curseur invisible scene::IMeshManipulator *manipulator = sceneManager->getMeshManipulator(); CShieldManager *shieldmanager = new CShieldManager(sceneManager,device->getTimer()); scene::ISceneNode * plane = sceneManager->addCubeSceneNode(0.0001f); scene::IAnimatedMeshSceneNode *battle_turtle1 = sceneManager->addAnimatedMeshSceneNode(sceneManager->getMesh("Data/model/dedale/dedale.b3d"), plane); scene::ISceneNode * planet = sceneManager->addSphereSceneNode(5,96); scene::ISceneNode * soleil = sceneManager->addSphereSceneNode(5,96); planet->setScale(vector3df(20,20,20)); planet->setPosition(vector3df(20000,0,0)); soleil->setScale(vector3df(20*18,20*18,20*18)); soleil->setPosition(vector3df(0,0,0)); soleil->setMaterialFlag(EMF_LIGHTING, false); lumiere->setPosition(soleil->getPosition()); battle_turtle1->setScale(core::vector3df(1,1,1)); battle_turtle1->setPosition(core::vector3df(20000,0,100)); battle_turtle1->setMaterialFlag(EMF_LIGHTING, true); shield_node = sceneManager->addAnimatedMeshSceneNode(sceneManager->getMesh("Data/model/dedale/shield_dedale.b3d"),battle_turtle1); shield_node->setMaterialTexture(0,driver->getTexture("Data/textures/water.jpg")); shield_node->setMaterialTexture(1,driver->getTexture("Data/textures/gradient_blinds.png")); planet->setMaterialTexture(0,driver->getTexture("Data/textures/terre.jpg")); soleil->setMaterialTexture(0,driver->getTexture("Data/textures/soleil.png")); manipulator->scaleTCoords(shield_node->getMesh(),core::vector2df(6,6),1); shield_node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,false); shield_node->setScale(core::vector3df(1,1,1)); shield_node->setVisible(false); scene::ITriangleSelector *selector = sceneManager->createTriangleSelector(shield_node->getMesh(),shield_node); selector = sceneManager->createTriangleSelector(shield_node->getMesh(),shield_node); shield_node->setTriangleSelector(selector); selector->drop(); scene::ITriangleSelector *selector1; shieldmanager->addShield(shield_node); FollowingCamera* MaCamera = new FollowingCamera(battle_turtle1, sceneManager,false, 50000,selector1,-3,0.5f,0,vector3df(7,2,0)); // Position initiale. MyEventReceiver receiver; device->setEventReceiver(&receiver); int lastFPS = -1; u32 lastMS = device->getTimer()->getRealTime(); while (device->run()) // la boucle de rendu { u32 difMs = device->getTimer()->getRealTime()-lastMS; lastMS = device->getTimer()->getRealTime(); f32 alignSpeed = difMs/16.0; if(lastMS%(rand()%20+30)==0) { core::vector3df source = vector3df(50,10,50); core::vector3df target = battle_turtle1->getPosition(); const core::line3df ray(source,target); core::vector3df result = shieldmanager->addImpact(shield_node, ray,radius*250,duration,impact_color); core::matrix4 trans = shield_node->getAbsoluteTransformation(); trans.makeInverse(); trans.transformVect(result); } event_manager(&receiver,battle_turtle1,plane ); driver->beginScene(true,true,SColor(0,200,200,200)); MaCamera->Update(); sceneManager->drawAll (); shieldmanager->drawAll(); driver->endScene (); } device->drop (); delete shieldmanager; delete MaCamera; return 0; } |
25-10-2010 23:32:23 |
C'est exactement sa et pour les commentaire c'est une habitude que je doit prendre désoler. |
C'est exactement ça et pour les commentaires c'est une habitude que je dois prendre désolé. |
25-10-2010 23:31:34 |
ok, si je peut me permettre une petit remarque au passage (mais le prend pas mal) ça manque un peut de commentaire ton code, ça devient un peut difficile à lire (enfin pour moi toujours). |
ok, si je peux me permettre une petit remarque au passage (mais le prend pas mal) ça manque un peu de commentaires ton code, ça devient un peu difficile à lire (enfin pour moi toujours).
|
25-10-2010 23:31:09 |
Excuse moi pour les balises ben quand je dit que sa bug ben la camera ne suit plus le vaisseau et quand je tourne avec le vaisseau ben il disparait. mais avec le code que j'ai mis il a pas de problème mais le vaisseau ne tourne pas comme il faut quand je monte ou descend. |
Excuse moi pour les balises ben quand je dit que sa bug ben la camera ne suit plus le vaisseau et quand je tourne avec le vaisseau ben il disparaît. mais avec le code que j'ai mis il a pas de problème mais le vaisseau ne tourne pas comme il faut quand je monte ou descends. |
25-10-2010 23:28:37 |
j'ai deja essaye sa mais le problème c'est que avec la camera 3émé personne que j'ai sans fait un joli bug mais je vais retenter. |
j'ai déjà essayé ça mais le problème c'est que avec la camera 3eme personne que j'ai sans fait un joli bug mais je vais retenter.
|
25-10-2010 23:27:43 |
ok je vois ce que tu veux dire, |
ok je vois ce que tu veux dire,
|
25-10-2010 23:26:37 |
Pour ma 2eme question je voudrais savoir comment faire pour que les axes de rotation du mesh, de l'objet que je contrôle (vaisseaux spatiale) ne tourne pas avec le mesh. |
Pour ma 2eme question je voudrais savoir comment faire pour que les axes de rotation du mesh, de l'objet que je contrôle (vaisseaux spatiale) ne tournent pas avec le mesh.
|
25-10-2010 23:25:26 |
pour ta 1er question jette un oeil par là: |
Pour ta 1ere question jette un œil par là:
|
25-10-2010 23:24:47 |
Bonjour je cherche le calcule a faire pour que mon mesh avance selon la rotation Y et Z. |
Bonjour je cherche le calcule à faire pour que mon mesh avance selon la rotation Y et Z.
|
25-10-2010 23:24:02 |