Inserting a jpg image and rotating it?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

There's no way we can guess what's wrong. If you post your source - your entire source - and ideally your resources as well, then we can help.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

wats wrong with sayin if im missin a "using namespace," yea i dont know a lot about c++ but i do know java and in java u hav to import components to use there classes so in c++ if i dont hav a namespace i might not be able to use wat i need to.
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

(node1 is a car that moves wen i press w,s,a,d.)
(node2 is is a car with no wheels)
(node3 is the wheel)- needs to rotate!
right anyway heres the code:

Code: Select all

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

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

#pragma comment(lib, "Irrlicht.lib")

scene::ISceneNode* node1 = 0;
scene::ISceneNode* node2 = 0;
scene::ISceneNode* node3 = 0;
IrrlichtDevice* device = 0;

    void rotatewheel()
    {
      static float rotation = 10;
      node3->setRotation(vector3df(rotation,10,10)); // or on the z axis if necessary
      rotation++;
    }

class MyEventReceiver : public IEventReceiver
{//event class started
public:
	virtual bool OnEvent(const SEvent& event)
	{//This is where if statements are added
		if (node1 != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
		{//The switch event is called
			switch(event.KeyInput.Key)
			{//What keys are going to be pressed
			case KEY_KEY_W:
			case KEY_KEY_S:
				{//What the switch is going to do
					core::vector3df v = node1->getPosition();
					v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
					node1->setPosition(v);
				}//Switch actions are closed
				return true;
			}//Cases are closed
		}//The switch event is closed
        if (node1 != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
		{//The switch event is called
			switch(event.KeyInput.Key)
			{//What keys are going to be pressed
			case KEY_KEY_A:
			case KEY_KEY_D:
				{//What the switch is going to do
					core::vector3df u = node1->getPosition();
					u.Z += event.KeyInput.Key == KEY_KEY_D ? 2.0f : -2.0f;
					node1->setPosition(u);
				}//Switch actions are closed
				return true;
			}//Cases are closed
		}//The switch event is closed

		return false;
	}//This is where if statements are closed
};//event class ended

int main()
{
	video::E_DRIVER_TYPE driverType;

	printf("Please select the driver you want for this example:\n"\
		" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
		" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
		" (f) NullDevice\n (otherKey) exit\n\n");

	char i;
	std::cin >> i;

	switch(i)
	{
		case 'a': driverType = video::EDT_DIRECT3D9;break;
		case 'b': driverType = video::EDT_DIRECT3D8;break;
		case 'c': driverType = video::EDT_OPENGL;   break;
		case 'd': driverType = video::EDT_SOFTWARE; break;
		case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
		case 'f': driverType = video::EDT_NULL;     break;
		default: return 1;
	}

	MyEventReceiver receiver;

	IrrlichtDevice* device = createDevice( driverType, core::dimension2d<s32>(640, 480),
		16, false, false, false, &receiver);

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

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

    smgr->loadScene("../../media/mygame.irr");

	scene::ISceneNode* node = 0;

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

//animation
    scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/Alien.x"));

	if (anms)
	{
		scene::ISceneNodeAnimator* anim =
        smgr->createFlyStraightAnimator(core::vector3df(100,0,60),
        core::vector3df(-100,0,60), 2500, true);
		anms->addAnimator(anim);
		anim->drop();
        anms->setMaterialFlag(video::EMF_LIGHTING, false);

		anms->setFrameLoop(160, 183);
		anms->setAnimationSpeed(40);
		anms->setMD2Animation(scene::EMAT_RUN);

		anms->setRotation(core::vector3df(0,180.0f,0));
		anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
	}
//end of animation

//impreza car
    node1 = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/impreza/impreza.3ds"));
	if(node1)
	{
	node1->setPosition(core::vector3df(0,0,30));
	node1->setMaterialFlag(video::EMF_LIGHTING, false);
	}
//end of impreza car

//F1 car
    node2 = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/f1_car.x"));

    if(node2)
	{
	node2->setRotation(core::vector3df(90,0,0));
	node2->setPosition(core::vector3df(0,0,100));
	node2->setMaterialFlag(video::EMF_LIGHTING, false);
	}
//end of F1 car

//wheels
    node3 = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/wheel.x"));

    if(node3)
    {
    node3->setRotation(core::vector3df(90,0,0));
	node3->setPosition(core::vector3df(0,50,100));
	node3->setMaterialFlag(video::EMF_LIGHTING, false);
	}

//end of wheels

//camera
	scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
	device->getCursorControl()->setVisible(false);
//end of camera

	int lastFPS = -1;

	while(device->run())

	if (device->isWindowActive())
	{
		driver->beginScene(true, true, video::SColor(0,200,200,200));
		smgr->drawAll();
		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			core::stringw str = L"My Game [";
			str += driver->getName();
			str += "] FPS:";
			str += fps;

			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}

	device->drop();
	return 0;
}
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

like I said, you're missing the very basics !!! :roll:
and I meant this in general... ;)
also this (with the namespaces) is wrong !!!
if you don't use namespaces, the functions (and other stuff) in the namespace are still avilable...

this all is explained in the tutorial link I posted:
http://www.cplusplus.com/doc/tutorial/namespaces.html
!!! so please do some researches there now !!!


EDIT: about your code: how should the wheel rotate if you never call the rotatewheel() function !?!?! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

ok well i did say i dont really know c++ i dont want to learn it yet so stop sayin that and i hav called the rotatewheel() function on the 13th line
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Ravi08 wrote:i hav called the rotatewheel() function on the 13th line
Uh, no. You've defined the function, but there's no call to it in the code that you posted.

You'll want to add a call to rotatewheel() inside your main while(device->run()) loop.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Ravi08 wrote:ok well i did say i dont really know c++ i dont want to learn it yet so stop sayin that and i hav called the rotatewheel() function on the 13th line
If you don't want to learn C++, its going to be very hard to program with a C++ engine.

At line 13 you define the rotatewheel() function, but that's it. You have to actually call it during your main loop for it to do anything.

Read through the tutorial Acki posted and it will make everything ridiculously easier. I know from experience.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Ravi08 wrote:ok well i did say i dont really know c++ i dont want to learn it yet
than you're realy at the wrong place !!! :roll:
I don't mean this forum, I mean with using a C++ library like Irrlicht !!! :lol:
if you realy want to create something with Irrlicht than you need to learn C++, at least the very basics !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

i know i need to learn it and thanks for the help
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

one last thing the code finnaly works and the wheel rotates but at the moment the wheel rotates in a massive circle and i tried enterin different numbers for the axis but they just change the axis so any advice on how to make the wheel rotate but not rotate in a massive circle.

If u dont understand plz post u dont then i will create a video a post it on youtube.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

this is probably because the pivot/origin of the mesh is not at its centre...
you'll have to change this with your 3d editor... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

how the f**k did u know that?

and thanks very much for all of ur help
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Ravi08 wrote:how the f**k did u know that?
well, I'm a mentalist !!! :lol:

no, seriously: learning, experience and sometimes just guessing... :P
and in this case it was my experience with modelling that made my guess to have a 99.9% chance to be right... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply