Prey portals like

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Prey portals like

Post by Blizzard »

Hello! 8)
I'm Santostefano Giovanni alias "blizzard"!

I've developed a class for make the portals similar to Prey's portals. I've sent the code to Nickolaus Gebhardt but I want to release it in every case.

I belive that I can attach it to the forum but I can't include any rar files here! :cry:

If I find a link tu upload the source I write soon.
If I can't find a link you can send me an e-mail and I send all directly if I can [/img][/list]
Everyone for the game and the game for everyone
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

TRY THE CODE

Post by Blizzard »

Tanks to my friend Leonardo that host the file 8)

Here you can download the source code.
Remember that you must have DX9 SDK to work with it

http://www.kxt.it/BLIZPORTALSsource.rar

This is the url of the pack is a small rar

_______________________________________________________________________
Everyone for the game and the game for everyone
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

hi, I tried downloading but winrar won't open the file. it is 96,777 bytes, is this correct?
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Post by Blizzard »

Hi,
yes, the size is correct.... I tink the archive is corrupted.
Probably I upload a new version today... maybe zip file.

Sorry, try this evening :cry:
Everyone for the game and the game for everyone
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Rapid solution

Post by Blizzard »

Before I up the code... here I post it

Code: Select all

//----------------------------------------------
// File: BlizPortal.h
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------


#ifndef BLIZPORTAL
#define BLIZPORTAL

#include <d3d9.h>
#include <d3dx9.h>

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

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

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

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")


class BlizPortal{

	public:
		IrrlichtDevice* device; //pointer to the irr device

		LPDIRECT3D9             d3d; // pointer to D3D interface
		LPDIRECT3DDEVICE9       d3ddev; // pointer to D3D device

		ICameraSceneNode* camera; //active camera of the scene
		ICameraSceneNode* cP1; //camera of the first portal
		ICameraSceneNode* cP2; //camera of the second portal

		core::vector3df dp1c; //deltaPosition between portal 1 and the camera
		core::vector3df dp2c; //deltaPosition between portal 2 and the camera

		IAnimatedMeshSceneNode* portal1; //scene node of the first portal
		float Radius1; //radius of the object that compose fist portal
		IAnimatedMeshSceneNode* portal2; //scene node of the second portal
		float Radius2; //radius of the object that compose second portal

		int is_p1_active; //it assumes 1 if the first portal il active
		int is_p2_active; //it assumes 1 if the second portal il active
		int passed; //this int contains the portal that you have passed


	public:

		//Constructor
		BlizPortal();

		//Destructor
		~BlizPortal();


		//Baically in this version the lots of initialization
		//is made by the user such as in the sample.
		//This procedure initialize only the d3d pointers
		//and the delta vectors.
		//Before using this function the user/programmer must define
		//the device, the camera and the nodes of the portals
		void BP_init();

		//This procedure render both the portals! ^_^
		//It must be called after the smgr->drawAll()
		//in the scene
		void BP_render_portals();

		//This procedure render the portal! ^_^
		void BP_render_portal(IAnimatedMeshSceneNode* portal, ICameraSceneNode* cP );

		//This procedure verify if the camera pass through a portal
		//if true, she actives the transfer and set to 0 the active value
		//of the portal were you are transfered.
		//If you exit from the portal the portal is reactivated so you
		//can use it to go in the previous zone
		//
		//NOTE: it's better that you define your own procedure to use
		//portals. If, for example, you are programming a 3rd person shooter
		//this function is not correct, because she evaluates the translation
		//of the camera.
		void BP_use_portals();



};


#endif

//----------------------------------------------
// File: BlizPortal.h
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Code: Select all

//----------------------------------------------
// File: BlizPortal.cpp
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------


#include "BlizPortal.h"


//Constructor
BlizPortal::BlizPortal(){}

//Destructor
BlizPortal::~BlizPortal(){}


//Baically in this version the lots of initialization
//is made by the user such as in the sample.
//This procedure initialize only the d3d pointers
//and the delta vectors.
//Before using this function the user/programmer must define
//the device, the cameras and the nodes of the portals
void BlizPortal::BP_init(){
	IVideoDriver* driver = device->getVideoDriver();

	d3d=(driver->getExposedVideoData()).D3D9.D3D9;
	d3ddev=(driver->getExposedVideoData()).D3D9.D3DDev9;

	//set the portals unvisible
	//NOTE: PORTALS MUST BE UNVISIBLE!!!!!!
	portal1->setVisible(false);
	portal2->setVisible(false);
}

//This procedure render both the portals! ^_^
//It must be called after the smgr->drawAll()
//in the scene
void BlizPortal::BP_render_portals(){

	//Setting of the cameras
	//--------------------------------------------------------
	dp2c=camera->getPosition() - portal1->getPosition();
	dp1c=camera->getPosition() - portal2->getPosition();

	cP1->setPosition(portal1->getPosition()+dp1c);
	cP1->setRotation(camera->getRotation());

	cP2->setPosition(portal2->getPosition()+dp2c);
	cP2->setRotation(camera->getRotation());
	//---------------------------------------------------------

	if(is_p1_active==1){
		portal2->setVisible(false);
		BP_render_portal(portal1,cP2);
	}
	if(is_p2_active==1){
		portal1->setVisible(false);
		BP_render_portal(portal2,cP1);
	}


}

//This procedure render the portal! ^_^
void BlizPortal::BP_render_portal(IAnimatedMeshSceneNode* portal, ICameraSceneNode* cP ){

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


	//SETTING THE STENCIL BUFFER
	//------------------------------------------------------------------
    d3ddev->SetRenderState( D3DRS_STENCILENABLE, TRUE );
    d3ddev->SetRenderState( D3DRS_STENCILFUNC,     D3DCMP_ALWAYS );
    d3ddev->SetRenderState( D3DRS_STENCILREF,      0x1 );
    d3ddev->SetRenderState( D3DRS_STENCILMASK,     0xffffffff );
    d3ddev->SetRenderState( D3DRS_STENCILWRITEMASK,0xffffffff );
    d3ddev->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
    d3ddev->SetRenderState( D3DRS_STENCILFAIL,  D3DSTENCILOP_KEEP );
    d3ddev->SetRenderState( D3DRS_STENCILPASS,  D3DSTENCILOP_REPLACE );

    d3ddev->SetRenderState( D3DRS_ZWRITEENABLE,  FALSE );
	//-------------------------------------------------------------------

	//rendering the portal in the stencil buffer
	//-------------------------------------------
	portal->setVisible(true);
	camera->render();
	portal->render();
	portal->setVisible(true);
	//-------------------------------------------

	//rendering the scene connected to the portal
	//-------------------------------------------------------------------
    d3ddev->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
    d3ddev->SetRenderState( D3DRS_STENCILFUNC,  D3DCMP_EQUAL );
    d3ddev->SetRenderState( D3DRS_STENCILPASS,  D3DSTENCILOP_KEEP );
 
    // Clear the zbuffer
    d3ddev->Clear( 0L, NULL, D3DCLEAR_ZBUFFER, 0L, 1.0f, 0L );

	smgr->setActiveCamera(cP);
	smgr->drawAll(); 
	//--------------------------------------------------------------------


	// Restore render states
	//---------------------------------------------------------------------
    d3ddev->SetRenderState( D3DRS_STENCILENABLE,    FALSE );
    d3ddev->SetRenderState( D3DRS_CLIPPLANEENABLE,  0x00 );
    
	smgr->setActiveCamera(camera);
	//----------------------------------------------------------------------
}

//This procedure verify if the camera pass through a portal
//if true, she actives the transfer and set to 0 the active value
//of the portal were you are transfered.
//If you exit from the portal the portal is reactivated so you
//can use it to go in the previous zone
//
//NOTE: it's better that you define your own procedure to use
//portals. If, for example, you are programming a 3rd person shooter
//this function is not correct, because she evaluates the translation
//of the camera.
void BlizPortal::BP_use_portals(){

	core::line3d<f32> line;

	if(is_p1_active==1){
		line.start = camera->getPosition();
		line.end=portal1->getPosition();

		//player is in the portal
		if(line.getLength()<Radius1){
			camera->setPosition(cP2->getPosition());

			is_p1_active=0;
			is_p2_active=0;

			passed=1;

			return;

		}

	}
	else if(is_p2_active==1){
		line.start = camera->getPosition();
		line.end=portal2->getPosition();

		//player is in the portal
		if(line.getLength()<Radius2){
			camera->setPosition(cP1->getPosition());

			is_p1_active=0;
			is_p2_active=0;

			passed=2;

			return;
		}
	}




	//active portals
	if(is_p1_active==0 && passed==2){
		line.start = camera->getPosition();
		line.end=portal1->getPosition();

		//player is in the portal
		if(line.getLength()>Radius1){
			is_p1_active=1;
		}

	}
	
	if(is_p2_active==0 && passed==1){
		line.start = camera->getPosition();
		line.end=portal2->getPosition();

		//player is in the portal
		if(line.getLength()>Radius2){
			is_p2_active=1;

		}
	}



}

//----------------------------------------------
// File: BlizPortal.cpp
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
HERE THE EXAMPLE
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Code: Select all

/*
This Tutorial shows how to load a Quake 3 map into the
engine, create a SceneNode for optimizing the speed of
rendering and how to create a user controlled camera.

Lets start like the HelloWorld example: We include
the irrlicht header files and an additional file to be able
to ask the user for a driver type using the console.
*/
#include <irrlicht.h>
#include <iostream>


#include "BlizPortal.h"

/*
As already written in the HelloWorld example, in the Irrlicht
Engine, everything can be found in the namespace 'irr'. 
To get rid of the irr:: in front of the name of every class,
we tell the compiler that we use that namespace from now on, 
and we will not have to write that 'irr::'.
There are 5 other sub namespaces 'core', 'scene', 'video',
'io' and 'gui'. Unlike in the HelloWorld example,
we do not a 'using namespace' for these 5 other namespaces
because in this way you will see what can be found in which
namespace. But if you like, you can also include the namespaces
like in the previous example. Code just like you want to.
*/
using namespace irr;

/*
Again, to be able to use the Irrlicht.DLL file, we need to link with the 
Irrlicht.lib. We could set this option in the project settings, but
to make it easy, we use a pragma comment lib:
*/
#pragma comment(lib, "Irrlicht.lib")

/*
Ok, lets start. Again, we use the main() method as start, not the
WinMain(), because its shorter to write.
*/
int main()
{
	/*
	Like in the HelloWorld example, we create an IrrlichtDevice with
	createDevice(). The difference now is that we ask the user to select 
	which hardware accelerated driver to use. The Software device would be
	too slow to draw a huge Quake 3 map, but just for the fun of it, we make
	this decision possible too.
	*/

	// ask user for driver

	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) Apfelbaum 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_SOFTWARE2;break;
		case 'f': driverType = video::EDT_NULL;     break;
		default: return 1;
	}	

	// create device and exit if creation failed

	IrrlichtDevice *device =
		createDevice(driverType, core::dimension2d<s32>(1024, 768),false,true,true);

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

	/*
	Get a pointer to the video driver and the SceneManager so that
	we do not always have to write device->getVideoDriver() and
	device->getSceneManager().
	*/
	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	/*
	To display the Quake 3 map, we first need to load it. Quake 3 maps
	are packed into .pk3 files wich are nothing other than .zip files.
	So we add the .pk3 file to our FileSystem. After it was added,
	we are able to read from the files in that archive as they would
	directly be stored on disk.
	*/
	device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");

	/* 
	Now we can load the mesh by calling getMesh(). We get a pointer returned
	to a IAnimatedMesh. As you know, Quake 3 maps are not really animated,
	they are only a huge chunk of static geometry with some materials
	attached. Hence the IAnimated mesh consists of only one frame,
	so we get the "first frame" of the "animation", which is our quake level
	and create an OctTree scene node with it, using addOctTreeSceneNode().
	The OctTree optimizes the scene a little bit, trying to draw only geometry
	which is currently visible. An alternative to the OctTree would be a 
	AnimatedMeshSceneNode, which would draw always the complete geometry of 
	the mesh, without optimization. Try it out: Write addAnimatedMeshSceneNode
	instead of addOctTreeSceneNode and compare the primitives drawed by the
	video driver. (There is a getPrimitiveCountDrawed() method in the 
	IVideoDriver class). Note that this optimization with the Octree is only
	useful when drawing huge meshes consiting of lots of geometry.
	*/
	scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
	scene::ISceneNode* node = 0;
	
	if (mesh)
		node = smgr->addOctTreeSceneNode(mesh->getMesh(0));

	/*
	Because the level was modelled not around the origin (0,0,0), we translate
	the whole level a little bit.
	*/
	if (node)
		node->setPosition(core::vector3df(-1300,-144,-1249));


	node->setScale(core::vector3df(2,2,2));



	smgr->addSkyBoxSceneNode(
	driver->getTexture("../../media/irrlicht2_up.jpg"),
	driver->getTexture("../../media/irrlicht2_dn.jpg"),
	driver->getTexture("../../media/irrlicht2_lf.jpg"),
	driver->getTexture("../../media/irrlicht2_rt.jpg"),
	driver->getTexture("../../media/irrlicht2_ft.jpg"),
	driver->getTexture("../../media/irrlicht2_bk.jpg"));
	/*
	Now we only need a Camera to look at the Quake 3 map.
	And we want to create a user controlled camera. There are some
	different cameras available in the Irrlicht engine. For example the 
	Maya Camera which can be controlled compareable to the camera in Maya:
	Rotate with left mouse button pressed, Zoom with both buttons pressed,
	translate with right mouse button pressed. This could be created with
	addCameraSceneNodeMaya(). But for this example, we want to create a 
	camera which behaves like the ones in first person shooter games (FPS).
	*/
	ICameraSceneNode* c=smgr->addCameraSceneNodeFPS();
	c->setPosition(core::vector3df(1837,122,1420));
	c->setRotation(core::vector3df(0,270,0));

	ICameraSceneNode* cp1=smgr->addCameraSceneNodeFPS(0,0,0);
	ICameraSceneNode* cp2=smgr->addCameraSceneNodeFPS(0,0,0);

	/*
	The mouse cursor needs not to be visible, so we make it invisible.
	*/

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

	/*
	We have done everything, so lets draw it. We also write the current
	frames per second and the drawn primitives to the caption of the
	window. The 'if (device->isWindowActive())' line is optional, but 
	prevents the engine render to set the position of the mouse cursor 
	after task switching when other program are active.
	*/
	int lastFPS = -1;




	BlizPortal p; //declare a BlizPortal

	p.device=device;

	//example
	p.camera=c;
	p.cP1=cp1;
	p.cP2=cp2;

	//NOTE: the portals can't be both activated 
	p.is_p1_active=0;
	p.is_p2_active=1;
		
	//example
	p.portal1=smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/earth.x"));
	p.portal1->setScale(core::vector3df(150,150,150));
	p.portal1->setPosition(core::vector3df(1328,828,2195));
	p.portal1->setMaterialFlag(EMF_LIGHTING,false);
	p.Radius1=200;

	p.portal2=smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/earth.x"));
	p.portal2->setScale(core::vector3df(150,150,150));
	p.portal2->setPosition(core::vector3df(1468,122,1420));
	p.portal2->setMaterialFlag(EMF_LIGHTING,false);
	p.Radius2=200;
	
	p.BP_init();

	while(device->run())
	if (device->isWindowActive())
	{

		smgr->setActiveCamera(c);
		driver->beginScene(true, true, video::SColor(0,0,200,200));

		p.BP_use_portals();

		//pre render operation
		p.d3ddev->SetRenderState( D3DRS_CLIPPLANEENABLE,  false );
		
		smgr->drawAll();

		//render mirror
		p.BP_render_portals();


		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;
		}
	}

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

Remember to link the sdk of dx9. I've used a old release of DX but I don't think that create problems.

In the rar that I hope to upload, you can find a readme
Everyone for the game and the game for everyone
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post by Ced666 »

I don't know 3DRealms. What are these portals supposed to do ?
Do you have any screenshot ?
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Prey portals

Post by Blizzard »

a portal is a gateway for another part of the scene.
You can pass through the portal and you can go in a completely other location.

Image

this is a small image.

If I can I upload my portal image

You don't know 3d realms???? :( you don't know Duke Nukem, Shadow Warriors, Kommander Keen (Apogee),Rise of the triad,.. ....
Prey is developad by 3dRealms/Human head
Everyone for the game and the game for everyone
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

BlizPortals

Post by Blizzard »

Here there are my portals.... there are not so beautyfull as prey but they works and I'm happy 8)



The screen is taked from the example application. try to pass trough it, it's beautyfull

http://tk.files.storage.msn.com/x1pnp_r ... GRX7SaJ9vk
Everyone for the game and the game for everyone
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post by TheRLG »

That's fricken beautiful dude. Keep up the good work, we need to be putting Prey to shame ASAP!
rooly
Posts: 224
Joined: Tue Oct 25, 2005 4:32 pm
Location: Louisiana, USA, backwater country
Contact:

Post by rooly »

that is freakin awesome!

if you wanna make it pretty like that pic you posted, just add a few meshes and textures. get 2 animated tex's(for the 'glowing ring', 1 from the side, another fromt the front), a directional strobe light, and a surrounding non-collision mesh.

sounds like a lot, but its nothing more than 3 pictures, a light, and a nurbs ring! you can set it all inside one class, the camera init, and everything, with a pointer reference to its counterpart!

also, dont' forget unreal in your examples
When banks compete, you win.
When ISPs compete, you win.
When electronics retailers compete, you win.
When governments compete...you get drafted.
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Post by Blizzard »

8) Thanks to you all!!!!

I've think to use the billboarding to make a ring un the portal, but I've not implemented that feature, because if you see the implementation you can use as portal a sphere, a flat mesh or... anything you want such as a teapot or a walking man ^_^

The geometry you select (can you imagin a walking man as portal??), modify the ring glow that surround it.

For the other particulars you are right, if I've time I implement them....

Anyone ask to me the license of the code release
I write a thing:
I've not put a license on the code of the portals but if someone use this code, please write in a print screen or in a readme file:

"This application use BlizPortals, implemented by Santostefano "Blizzard" Giovanni
contact: idmgiovanni@libero.it"


If you do that I'm happy
For the other things you can use, modify or release this code without limits ^_^
Everyone for the game and the game for everyone
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

New version

Post by Blizzard »

8)
Here is a new version of the class, as in the previous posts they ask

I've implemented constructor & destructor
I've made an overloaded method for automatic initialization

Code: Select all

//----------------------------------------------
// File: BlizPortal.h v0.1.1
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------


#ifndef BLIZPORTAL
#define BLIZPORTAL

#include <d3d9.h>
#include <d3dx9.h>

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

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

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

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")


class BlizPortal{

	public:
		IrrlichtDevice* device; //pointer to the irr device

		LPDIRECT3D9             d3d; // pointer to D3D interface
		LPDIRECT3DDEVICE9       d3ddev; // pointer to D3D device

		ICameraSceneNode* camera; //active camera of the scene
		ICameraSceneNode* cP1; //camera of the first portal
		ICameraSceneNode* cP2; //camera of the second portal

		core::vector3df dp1c; //deltaPosition between portal 1 and the camera
		core::vector3df dp2c; //deltaPosition between portal 2 and the camera

		IAnimatedMeshSceneNode* portal1; //scene node of the first portal
		float Radius1; //radius of the object that compose fist portal
		IAnimatedMeshSceneNode* portal2; //scene node of the second portal
		float Radius2; //radius of the object that compose second portal

		int is_p1_active; //it assumes 1 if the first portal il active
		int is_p2_active; //it assumes 1 if the second portal il active
		int passed; //this int contains the portal that you have passed


	public:

		//Constructor
		BlizPortal();
		BlizPortal(IrrlichtDevice* dev);


		//Destructor
		~BlizPortal();

		//Baically in this version the lots of initialization
		//is made by the user such as in the sample.
		//This procedure initialize only the d3d pointers
		//and the delta vectors.
		//Before using this function the user/programmer must define
		//the device, the cameras and the nodes of the portals
		void BP_init();

		//Baically in this version the lots of initialization
		//is made by the user such as in the sample.
		//This procedure initialize only the d3d pointers
		//and the delta vectors.
		//Before using this function the user/programmer must define
		//the device
		//
		//fileM1 is the filename of the mesh that you want to load in the
		//first portal node
		//fileM2 is the filename of the mesh that you want to load in the
		//second portal node
		void BP_init(char* fileM1, char* fileM2);

		//This procedure render both the portals! ^_^
		//It must be called after the smgr->drawAll()
		//in the scene
		void BP_render_portals();

		//This procedure render the portal! ^_^
		void BP_render_portal(IAnimatedMeshSceneNode* portal, ICameraSceneNode* cP );

		//This procedure verify if the camera pass through a portal
		//if true, she actives the transfer and set to 0 the active value
		//of the portal were you are transfered.
		//If you exit from the portal the portal is reactivated so you
		//can use it to go in the previous zone
		//
		//NOTE: it's better that you define your own procedure to use
		//portals. If, for example, you are programming a 3rd person shooter
		//this function is not correct, because she evaluates the translation
		//of the camera.
		void BP_use_portals();



};


#endif

//----------------------------------------------
// File: BlizPortal.h v0.1.1
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------

Code: Select all

//----------------------------------------------
// File: BlizPortal.cpp v0.1.1
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------


#include "BlizPortal.h"


//Constructor
BlizPortal::BlizPortal(){
	device=0;
	d3d=0; 
	d3ddev=0; 
	camera=0; 
	cP1=0; 
	cP2=0; 
	portal1=0; 
	portal2=0;
}

BlizPortal::BlizPortal(IrrlichtDevice* dev){
	device=dev;
	d3d=0; 
	d3ddev=0; 
	camera=0; 
	cP1=0; 
	cP2=0; 
	portal1=0; 
	portal2=0;
}

//Destructor
BlizPortal::~BlizPortal(){
	device=0;
	d3d=0; 
	d3ddev=0; 
	camera->drop(); 
	cP1->drop(); 
	cP2->drop(); 
	portal1->drop(); 
	portal2->drop();
}

//Baically in this version the lots of initialization
//is made by the user such as in the sample.
//This procedure initialize only the d3d pointers
//and the delta vectors.
//Before using this function the user/programmer must define
//the device, the cameras and the nodes of the portals
void BlizPortal::BP_init(){
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	d3d=(driver->getExposedVideoData()).D3D9.D3D9;
	d3ddev=(driver->getExposedVideoData()).D3D9.D3DDev9;

	//set the portals unvisible
	//NOTE: PORTALS MUST BE UNVISIBLE!!!!!!
	portal1->setVisible(false);
	portal2->setVisible(false);
}


//Baically in this version the lots of initialization
//is made by the user such as in the sample.
//This procedure initialize only the d3d pointers
//and the delta vectors.
//Before using this function the user/programmer must define
//the device
//
//fileM1 is the filename of the mesh that you want to load in the
//first portal node
//fileM2 is the filename of the mesh that you want to load in the
//second portal node
void BlizPortal::BP_init(char* fileM1, char* fileM2){
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	d3d=(driver->getExposedVideoData()).D3D9.D3D9;
	d3ddev=(driver->getExposedVideoData()).D3D9.D3DDev9;

	//setting cameras
	camera=smgr->addCameraSceneNodeFPS();
	cP1=smgr->addCameraSceneNodeFPS(0,0,0);
	cP2=smgr->addCameraSceneNodeFPS(0,0,0);
	//activating main camera
	smgr->setActiveCamera(camera);

	//creating portals
	portal1=smgr->addAnimatedMeshSceneNode(smgr->getMesh(fileM1));
	portal2=smgr->addAnimatedMeshSceneNode(smgr->getMesh(fileM2));
	portal1->setMaterialFlag(EMF_LIGHTING,false);
	portal2->setMaterialFlag(EMF_LIGHTING,false);

	//set the portals unvisible
	//NOTE: PORTALS MUST BE UNVISIBLE!!!!!!
	portal1->setVisible(false);
	portal2->setVisible(false);
}

//This procedure render both the portals! ^_^
//It must be called after the smgr->drawAll()
//in the scene
void BlizPortal::BP_render_portals(){

	//Setting of the cameras
	//--------------------------------------------------------
	dp2c=camera->getPosition() - portal1->getPosition();
	dp1c=camera->getPosition() - portal2->getPosition();

	cP1->setPosition(portal1->getPosition()+dp1c);
	cP1->setRotation(camera->getRotation());

	cP2->setPosition(portal2->getPosition()+dp2c);
	cP2->setRotation(camera->getRotation());
	//---------------------------------------------------------

	if(is_p1_active==1){
		portal2->setVisible(false);
		BP_render_portal(portal1,cP2);
	}
	if(is_p2_active==1){
		portal1->setVisible(false);
		BP_render_portal(portal2,cP1);
	}


}

//This procedure render the portal! ^_^
void BlizPortal::BP_render_portal(IAnimatedMeshSceneNode* portal, ICameraSceneNode* cP ){

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


	//SETTING THE STENCIL BUFFER
	//------------------------------------------------------------------
    d3ddev->SetRenderState( D3DRS_STENCILENABLE, TRUE );
    d3ddev->SetRenderState( D3DRS_STENCILFUNC,     D3DCMP_ALWAYS );
    d3ddev->SetRenderState( D3DRS_STENCILREF,      0x1 );
    d3ddev->SetRenderState( D3DRS_STENCILMASK,     0xffffffff );
    d3ddev->SetRenderState( D3DRS_STENCILWRITEMASK,0xffffffff );
    d3ddev->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
    d3ddev->SetRenderState( D3DRS_STENCILFAIL,  D3DSTENCILOP_KEEP );
    d3ddev->SetRenderState( D3DRS_STENCILPASS,  D3DSTENCILOP_REPLACE );

    d3ddev->SetRenderState( D3DRS_ZWRITEENABLE,  FALSE );
	//-------------------------------------------------------------------

	//rendering the portal in the stencil buffer
	//-------------------------------------------
	portal->setVisible(true);
	camera->render();
	portal->render();
	portal->setVisible(true);
	//-------------------------------------------

	//rendering the scene connected to the portal
	//-------------------------------------------------------------------
    d3ddev->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
    d3ddev->SetRenderState( D3DRS_STENCILFUNC,  D3DCMP_EQUAL );
    d3ddev->SetRenderState( D3DRS_STENCILPASS,  D3DSTENCILOP_KEEP );
 
    // Clear the zbuffer
    d3ddev->Clear( 0L, NULL, D3DCLEAR_ZBUFFER, 0L, 1.0f, 0L );

	smgr->setActiveCamera(cP);
	smgr->drawAll(); 
	//--------------------------------------------------------------------


	// Restore render states
	//---------------------------------------------------------------------
    d3ddev->SetRenderState( D3DRS_STENCILENABLE,    FALSE );
    d3ddev->SetRenderState( D3DRS_CLIPPLANEENABLE,  0x00 );
    
	smgr->setActiveCamera(camera);
	//----------------------------------------------------------------------
}

//This procedure verify if the camera pass through a portal
//if true, she actives the transfer and set to 0 the active value
//of the portal were you are transfered.
//If you exit from the portal the portal is reactivated so you
//can use it to go in the previous zone
//
//NOTE: it's better that you define your own procedure to use
//portals. If, for example, you are programming a 3rd person shooter
//this function is not correct, because she evaluates the translation
//of the camera.
void BlizPortal::BP_use_portals(){

	core::line3d<f32> line;

	if(is_p1_active==1){
		line.start = camera->getPosition();
		line.end=portal1->getPosition();

		//player is in the portal
		if(line.getLength()<Radius1){
			camera->setPosition(cP2->getPosition());

			is_p1_active=0;
			is_p2_active=0;

			passed=1;

			return;

		}

	}
	else if(is_p2_active==1){
		line.start = camera->getPosition();
		line.end=portal2->getPosition();

		//player is in the portal
		if(line.getLength()<Radius2){
			camera->setPosition(cP1->getPosition());

			is_p1_active=0;
			is_p2_active=0;

			passed=2;

			return;
		}
	}




	//active portals
	if(is_p1_active==0 && passed==2){
		line.start = camera->getPosition();
		line.end=portal1->getPosition();

		//player is in the portal
		if(line.getLength()>Radius1){
			is_p1_active=1;
		}

	}
	
	if(is_p2_active==0 && passed==1){
		line.start = camera->getPosition();
		line.end=portal2->getPosition();

		//player is in the portal
		if(line.getLength()>Radius2){
			is_p2_active=1;

		}
	}



}

//----------------------------------------------
// File: BlizPortal.cpp v0.1.1
//
// Developer: Santostefano "Blizzard" Giovanni
//
// contact: idmgiovanni@libero.it
//
//
// BlizPortal is a class that implement 3dRealms Prey's like 
// portals using Microsoft DirectX9
// This class is created for drawing portals
// in irrlicht 3d (engine developed by
// Nickolaus Ghebardt)
//----------------------------------------------
Everyone for the game and the game for everyone
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

Nice! Maybe you can release a demo!
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

cool. I've done portal culling systems for both Irrlicht and Lightfeather, but I never implemented any of the special effects with portals. Nice
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Here the video

Post by Blizzard »

8) Here is a video of the BlizPortals. I've taken it with Fraps so it's slow and go to 30FPS when the normal speed is 80FPS. The compression is not good but you can see all.

THANKS FOR THE UPLOADING TO HIS PERSONAL SITE TO:
8) Di Vincenzo Luca "djsartanja" 8)

http://xoomer.virgilio.it/rioneronet/gi ... video).WMV

If this link doesn't work, visit


http://xoomer.virgilio.it/rioneronet/giovanni/

and download the file wmv :lol:
Everyone for the game and the game for everyone
Post Reply