Aktuelle Zeit: 29.03.2024, 10:55

Alle Zeiten sind UTC + 1 Stunde




Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Autor Nachricht
 Betreff des Beitrags: Kamera in falscher Richtung !?
BeitragVerfasst: 23.10.2010, 20:31 
Offline

Registriert: 16.10.2010, 10:33
Beiträge: 10
Hey, ich bins nochmal!

Ich hab jetzt Alles soweit wie ichs will NUR dass wenn ich meine cam bewege, Diese
in die entgegengesetzte Richtung der Bewegungung sieht!

Also wenn ich mich nach hinten (zurück bewege) schaut sie nach vorn (so solls ja sein) aber
wenn ich nach viorne gehe schaut sie nach hinten!

Zum besseren verständniss mal den Quellcode:

(bitte chrinic.bsp und chronic.pk3 mit anderen maps ersetzen (; )

Code:
#include <irrlicht.h>
#include <iostream>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

class MyEventReceiver : public IEventReceiver
{
public:
        // This is the one method that we have to implement
        virtual bool OnEvent(const SEvent& event)
        {
                // Remember whether each key is down or up
                if (event.EventType == irr::EET_KEY_INPUT_EVENT)
                        KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;

                return false;
        }

        // This is used to check whether a key is being held down
        virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                return KeyIsDown[keyCode];
        }
       
        MyEventReceiver()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }

private:
        // We use this array to store the current state of each key
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
};

int main()
{

   
    video::E_DRIVER_TYPE driverType;

    driverType = video::EDT_OPENGL;
   
    MyEventReceiver receiver;

   IrrlichtDevice* device = createDevice(driverType,
                        core::dimension2d<u32>(800, 600), 32, false, false, false, &receiver);


   if (device == 0)
      return 1; // could not create selected driver.


   video::IVideoDriver* driver = device->getVideoDriver();
   scene::ISceneManager* smgr = device->getSceneManager();


   device->getFileSystem()->addZipFileArchive("../../media/chronic.pk3");

   scene::IAnimatedMesh* mesh = smgr->getMesh("chronic.bsp");
   scene::ISceneNode* node = 0;
   

   if (mesh)
      node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
//      node = smgr->addMeshSceneNode(mesh->getMesh(0));

    node->setPosition(core::vector3df(-1300,-144,-1249));

   
   

   scene::ICameraSceneNode * cam = smgr-> addCameraSceneNode();
    cam->bindTargetAndRotation(true);

   device->getCursorControl()->setVisible(false);

   int lastFPS = -1;
    int Winkel = 0;
   
    const float Pi = (3.1415926535897932384626433832795);
   
    core::vector3df camPosition = cam->getPosition();
   core::vector3df camRotation = cam->getRotation();
   u32 then = device->getTimer()->getTime();

   
        // This is the movement speed in units per second.
        const f32 MOVEMENT_SPEED = 100.f;
   while(device->run())
   {
         camRotation = cam->getRotation();
         Winkel = (camRotation.Y - (int(camRotation.Y) / 360)*360);
         camPosition = cam->getPosition();
               
               
                const u32 now = device->getTimer()->getTime();
                const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
                then = now;
               
                if(receiver.IsKeyDown(irr::KEY_LEFT))
                        {
                        Winkel -= 5;
                        }
                       
                else if(receiver.IsKeyDown(irr::KEY_RIGHT))
                        {
                        Winkel += 5;
                        }
                       
                if(receiver.IsKeyDown(irr::KEY_UP))
                        {
                        camPosition.X = camPosition.X + MOVEMENT_SPEED * sin((Pi*Winkel/180));
                        camPosition.Z = camPosition.Z + MOVEMENT_SPEED * cos((Pi*Winkel/180));
                        }
               
                if(receiver.IsKeyDown(irr::KEY_DOWN))
                        {
                        camPosition.X = camPosition.X - MOVEMENT_SPEED * sin((Pi*Winkel/180));
                        camPosition.Z = camPosition.Z - MOVEMENT_SPEED * cos((Pi*Winkel/180));
                        }
               
                       
               
               
                if(receiver.IsKeyDown(irr::KEY_KEY_O))
                        camPosition.Y += MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_L))
                        camPosition.Y -= MOVEMENT_SPEED * frameDeltaTime;

                             
                camRotation.Y = Winkel;
                cam->setRotation(camRotation);
                cam->setPosition(camPosition);
               
                core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
            str += driver->getName();
            str += "]";            
                device->setWindowCaption(str.c_str());
               
                if (device->isWindowActive())
      {
         driver->beginScene(true, true, video::SColor(255,200,200,200));
         smgr->drawAll();
         driver->endScene();

         int fps = driver->getFPS();

         if (lastFPS != fps)
         {
            core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
            str += driver->getName();
            str += "] FPS:";
            str += fps;

            /*device->setWindowCaption(str.c_str());
            lastFPS = fps;*/
         }
      }
      else
         device->yield();
   }

   /*
   In the end, delete the Irrlicht device.
   */
   device->drop();
   return 0;
}

/*
That's it. Compile and play around with the program.
**/


Nach oben
 Profil  
 
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 

Alle Zeiten sind UTC + 1 Stunde


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 6 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de