Hey,
Well, i seem to have stumbled on a little trouble here. I need some help with classes. I thought you could use a seperate .cpp and .h file to setup a class (.h to do the defines and .cpp to code the functions), then just compile and your main file would recognise the class. Am I doing something wrong or can you not do this at all?
(I'm using MS Visual C++ .Net)
Thanks,
-Limb
How to use classes
Thanks, got it working but now i need some more help. Im getting 2 weird errors that i dont quite understand.... heres my code:
Main.cpp
eventReciever.cpp
eventReciever.h
ERROR 1: c:\Irrlicht\Learning Game\eventReciever.cpp(12): error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'irr::core::vector3d<T>'
with
[
T=irr::f32
]
ERROR 2: c:\Irrlicht\Learning Game\main - q3 map.cpp(18): error C2664: 'irr::createDevice' : cannot convert parameter 6 from 'MyEventReciever **__w64 ' to 'irr::IEventReceiver *'
Again, your help is appreciated.
Thanks,
-Limb
Main.cpp
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
//ISceneNode* node = 0;
#include "eventReciever.h"
int main()
{
MyEventReciever* reciever;
IrrlichtDevice *device = createDevice(video::EDT_DIRECTX9,
core::dimension2d<s32>(800, 600), 32, false, false, &reciever); [ERROR 2]
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
IGUIStaticText* gLocation = guienv->addStaticText(L"Location", rect<s32>(0,0,100,100), false, true, 0, 1);
device->getFileSystem()->addZipFileArchive("Media/map-20kdm2.pk3");
IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
if(mesh)
node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
if(node)
node->setPosition(vector3df(-1300, -144,-1429));
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
IAnimatedMesh* weaponMesh = smgr->getMesh("Media/armgun.3DS");
IAnimatedMeshSceneNode* weaponNode = smgr->addAnimatedMeshSceneNode( weaponMesh, camera);
weaponNode->setMaterialFlag(EMF_LIGHTING, false);
//weaponNode->setScale(core::vector3df(6,6,6));
weaponNode->setPosition(core::vector3df(-15,-15,10));
weaponNode->setRotation(core::vector3df(90,180,0));
weaponNode->setMaterialFlag(EMF_WIREFRAME, true);
// The final setup putting the camera in the level
// where it best suits the start of gameplay.
// camera->setPosition(camera->getPosition()); */
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
while(device->run())
{
wchar_t tmp[1024];
swprintf(tmp, 1024, L"Location: %d", camera->getPosition());
gLocation->setText(tmp);
driver->beginScene(true, true, SColor(0, 100, 100, 100));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
swprintf(tmp, 1024, L"Location: %d", camera->getAbsolutePosition());
gLocation->setText(tmp);
int fps = driver->getFPS();
if(lastFPS != fps)
{
swprintf(tmp, 1024, L"Quake 3 Map Example - Irrlich Engine (FPS: %d)", fps);
device->setWindowCaption(tmp);
lastFPS = fps;
}
}
device->drop;
return 0;
}
Code: Select all
#include "eventReciever.h"
bool MyEventReciever::OnEvent(SEvent event)
{
if(node != 0 && event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
vector3df v = node->getPosition; [ERROR 1]
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
}
};
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
ISceneNode* node = 0;
class MyEventReciever : public IEventReceiver
{
public:
virtual bool MyEventReciever::OnEvent(SEvent event);
};
with
[
T=irr::f32
]
ERROR 2: c:\Irrlicht\Learning Game\main - q3 map.cpp(18): error C2664: 'irr::createDevice' : cannot convert parameter 6 from 'MyEventReciever **__w64 ' to 'irr::IEventReceiver *'
Again, your help is appreciated.
Thanks,
-Limb
-Limb
Wrong type of pointer m8
should be
and you didn't call the function properly:
should be
My advice would be to read a big C++ book before trying to start a project in C++, it seems you don't quite get the rules of the language.
Code: Select all
MyEventReciever* reciever;
Code: Select all
MyEventReciever reciever;
Code: Select all
node->getPosition
Code: Select all
node->getPosition()
I get the language, just really dont remember the whole classes and pointers thing (I learned about them, but never used them much until now so I have forgotten about them, heh). Guess I should read up on them again and I'm always forgetting those stupid ()'s
Well, Thanks for the help. Time to go read up on my classes.
-Limb
Well, Thanks for the help. Time to go read up on my classes.
-Limb
-Limb