Mesh Disappearing During Rotation with 3rd Person Camera

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.
Post Reply
Colton450
Posts: 5
Joined: Sun Feb 14, 2010 11:22 pm

Mesh Disappearing During Rotation with 3rd Person Camera

Post by Colton450 »

So, I have a little marble racing game that I slapped together in a few minutes the other day. Besides the fact that my terrain splatting looks terrible due to the lack of attention, I have one major issue.

It appears that my marble mesh disappears when I rotate it (the camera is bound to the node's rotation for 3rd person effect) in any direction other than directly at or away from my lightscenenode...

I wanted to figure it out for myself, but I'm a little stumped. If anyone knows why this is happening, please tell me.

Here comes the source:

Code: Select all

#include <irrlicht/irrlicht.h>
#include "irrlicht/driverChoice.h"
#include <irrlicht/irrKlang.h>
using namespace irr;
using namespace irrklang;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "irrKlang.lib")
#endif
#define PI 3.141592653589793
core::vector3df nodePosition = core::vector3df(5000,10000,5500);
float ViewAngleHorX = (90.0);
float ViewAngleHorZ = (90.0);
inline double DegreeToRadian(double degrees)
{
	return (degrees / 180.f * PI);
}

class MyEventReceiver : public IEventReceiver
{
public:

	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType == irr::EET_KEY_INPUT_EVENT)
			KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;

		return false;
	}

	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:
	bool KeyIsDown[KEY_KEY_CODES_COUNT];
};


int main(int argc, char** argv)
{
    MyEventReceiver receiver;
    irr::SIrrlichtCreationParameters params;
	params.DriverType=video::EDT_OPENGL;
	params.WindowSize=core::dimension2d<u32>(1366,768);
	params.Fullscreen=false;
	params.Stencilbuffer=true;
	params.Bits=32;
	IrrlichtDevice* device = createDeviceEx(params);

	if (device == 0)
		return 1;

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	gui::IGUIEnvironment* env = device->getGUIEnvironment();
	
	ISoundEngine* engine = createIrrKlangDevice();

	if (!engine)
	{
		printf("Could not startup engine\n");
		return 0;
	}

	engine->play2D("media/WindBackground.mp3", true);

	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
    scene::IAnimatedMeshSceneNode* node = 0;

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

    node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("media/Ball.ms3d"),0);
        node->setScale(core::vector3df(2,2,2));
        node->setPosition(core::vector3df(nodePosition));
        node->getMaterial(0).NormalizeNormals = true;
        node->setMaterialFlag(video::EMF_LIGHTING, true);

    scene::IMeshSceneNode* node4 =
        smgr->addMeshSceneNode(smgr->getMesh("Media/Mountains/MountainTrack.b3d"));
    node4->setScale(core::vector3df(50,50,50));
    node4->setMaterialFlag(video::EMF_LIGHTING, true);

    scene::ICameraSceneNode* camera =
		smgr->addCameraSceneNode(node, core::vector3df(100,0,-500), nodePosition);
		camera->setFarValue(100000000000000.f);

	env->getSkin()->setFont(env->getFont("media/fontlucida.png"));

    smgr->setAmbientLight(video::SColor(0,150,150,150));

	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
    scene::ITriangleSelector* selector
		= smgr->createTriangleSelector(smgr->getMesh("Media/Mountains/MountainTrack.b3d"),node4);
	node4->setTriangleSelector(selector);
    scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, node, core::vector3df(40,40,40),
		core::vector3df(0,-12.f,0),
		core::vector3df(0,0,0));
	selector->drop();

    scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture("media/skydome.jpg"),16,8,0.95f,2.0f);

	node->addAnimator(anim);
	anim->drop();

	scene::ISceneNode* node3 = 0;
	node3 = smgr->addLightSceneNode(0, core::vector3df(-1000,800000,400000),
		video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 80000000.0f);

    device->setEventReceiver(&receiver);
	int lastFPS = -1;

	u32 then = device->getTimer()->getTime();
    float Speed=0;

	while(device->run())
	{
		const u32 now = device->getTimer()->getTime();
		const f32 frameDeltaTime = (f32)(now - then) / 1000.f;
		then = now;

		core::vector3df nodePosition = node->getPosition();
        core::vector3df oldnodePosition = node->getPosition();
        nodePosition.X += Speed * cos(DegreeToRadian(ViewAngleHorX-90));
        nodePosition.Z += Speed * sin(DegreeToRadian(ViewAngleHorX+90));
        Speed -= .02 * Speed * frameDeltaTime;
        node->setAnimationSpeed(Speed*3);

		if(receiver.IsKeyDown(irr::KEY_SPACE))
			Speed+=5*frameDeltaTime;
		if(receiver.IsKeyDown(irr::KEY_KEY_S))
			Speed-=10*frameDeltaTime;
		if(receiver.IsKeyDown(irr::KEY_KEY_A))
		{
			ViewAngleHorX-=35*frameDeltaTime;
		}
		if(receiver.IsKeyDown(irr::KEY_KEY_D))
		{
			ViewAngleHorX+=35*frameDeltaTime;
		}
		node->setPosition(nodePosition);
		node->setRotation(core::vector3df(ViewAngleHorX,0,ViewAngleHorZ));
        camera->setTarget(nodePosition);

		driver->beginScene(true, true, 0 );

		smgr->drawAll();
		env->drawAll();

		driver->endScene();

		int fps = driver->getFPS();
		if (lastFPS != fps)
		{
			core::stringw str = L"Marble Racer [";
			str += driver->getName();
			str += "] FPS:";
			str += fps;
			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}
    device->drop();

	return 0;
}
Colton450
Posts: 5
Joined: Sun Feb 14, 2010 11:22 pm

Post by Colton450 »

Am I missing any information that might be necessary to solve this issue? I'm STILL stumped. Please post any ideas you guys have; I am open to just about any solution at this point.
1k1
Posts: 3
Joined: Tue Apr 27, 2010 4:06 pm

Post by 1k1 »

Check the bounding boxes....
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

by turning automatic culling off for the node you can also try and see f it's a culling problem:

Code: Select all

node->setAutomaticCulling(EAC_OFF);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply