"linked portal door"

Posted By: 3run

"linked portal door" - 01/11/16 22:27

Does anyone have an idea, how to create seamless portal effect (linked portal door)?
I have a raw idea, to do everything by hand, but it's very dirty grin

Anyway, I found a nice video demostraiting what I want to archive:
World Portals - What's the big deal?
And one thread from blender forums (with some little explanation, which is close to what I have in my mind):
Seamless transition between scenes


Any ideas are welcome! Best regards!

Edit: I found old posts made by Rackscha, he used to play with portals as I can see, and well as far as I see transition made the way I see it too, but he used shader to draw the portals if I got it correctly. And he used clipping shader, to cut off part of the model that went through the portal.
Posted By: Kartoffel

Re: "linked portal door" - 01/12/16 06:30

I once played around with it aswell.
If you're aiming for portals that can NOT be dynamically placed by the player like in Valve's 'Portal' it shouldn't be too hard (collision is going to be muuuch easier).

For it to work you basically have to render two scenes, one for the portal view and one from the player's perspective.
Posted By: 3run

Re: "linked portal door" - 01/12/16 09:19

This is how I see it (transition):

So when I move player to the linked portal, I set his new position to the linked portal position, but with offset which is relative to the first portal (so it's like mirroring his position relative to the portals, cause they are the same).

BUT I have two problems in my head with all this...

FiRST - how do I transit other objects, I mean how to handle visual part? I need to duplicate them, so it looks like object actually passing through the portal. To do this, I need to cut the object which penetrates the portal, and the rest of it in the linked portal as well (part which still didn't go through the portal yet).

Take a look at this picture.

Sure, I won't need this for the player (as he won't see himself in the game mechanics that I'm thinking off), but for other objects I will need them, especially in situations when the portal let's say placed in the middle of the room, so it's backside is visible.

SECOND - is performance. I imagine this like: view for each portal, view that shows what linked portal currently sees (relative to it's position and angle). But this is going to be pretty slow I guess... What do you guys think??


Best regards!
Posted By: Wjbender

Re: "linked portal door" - 01/12/16 11:11

http://stackoverflow.com/questions/13167192/portal-effect-in-opengl

clipping planes
Posted By: 3run

Re: "linked portal door" - 01/12/16 11:24

Will this article about opengl help me, since acknex uses direcx?

Edit: also I found out that using same model for two portals will lead into a problem with setting different views on skin of the each model, cause it seems that the skin of the second portal automatically changes by the skin of the first one. Using 'ent_clone' or 'ent_clonesk in' did not help so far.

Edit2: actually it seems, that I used 'ent_cloneskin' wrongly grin It works now.

Edit3:
Originally Posted By: Kartoffel
For it to work you basically have to render two scenes, one for the portal view and one from the player's perspective.
Kartoffel, can you explain more? I got views showing what linked portal see, but I need to add 'scene from player's perspective' I guess.
Posted By: sivan

Re: "linked portal door" - 01/12/16 14:12

I'm sure someone implemented it with 3dgs, then switched to Unity.
Posted By: 3run

Re: "linked portal door" - 01/12/16 14:14

Originally Posted By: sivan
I'm sure someone implemented it with 3dgs, then switched to Unity.
You can see that Rackscha got it working, here take a look at this video:
3D Gamestudio A8 Seamless Portal

I want to understand how it works but myself, but unfortunately I'm not that good as I expected. I can't get math part to work (adding player's perspective to the view angles/positions). I've read this old thread, and got angles working (thanks to Uhrwerk), but I can't get vector calculations.. the way they should work. And I can't pick right words to search internet for proper algorithm... smirk

Best regards!
Posted By: Wjbender

Re: "linked portal door" - 01/13/16 10:16

well , clipping planes aren't an opengl principle , thought you might start with research ,through questions from others with the same topic..

anyway directx has this https://msdn.microsoft.com/en-us/library/windows/desktop/bb174426(v=vs.85).aspx

but I am sure you need a shader , maby contact that guy .
Posted By: 3run

Re: "linked portal door" - 01/13/16 10:24

Originally Posted By: Wjbender
but I am sure you need a shader , maby contact that guy .
Thank you for links man, yes I wrote him a PM.

My best regards!
Posted By: Dico

Re: "linked portal door" - 01/14/16 20:02

i like portale style games , this method i tried to create it before but i stuck in views , i do all calculation for the mouvement exept the views i get problem in it .
i think the view need special shader smirk

This is what i did before :


so the camera portal 1 it move and rotate a l aid of player view .

i ask Rackscha before about the method and this what he say :
Originally Posted By: Rackscha
visual:
cameras are not rendered on a entity texture. entity renders a special color into the buffer for a screenshader to replace these pixels with the camera

the camera needs to keep an eye on the player and stay on the same line as the portal. so it moves along it.

and it is required to translate a relative point from one portal to another. which means making a position relative to a portal, rotating it back, then rotating it by the other portal and making it absolut again. Sabe goes for rotations
Posted By: 3run

Re: "linked portal door" - 01/14/16 20:14

Originally Posted By: Dico
i like portale style games , this method i tried to create it before but i stuck in views , i do all calculation for the mouvement exept the views i get problem in it .
i think the view need special shader smirk

This is what i did before :


so the camera portal 1 it move and rotate a l aid of player view .

i ask Rackscha before about the method and this what he say :
Originally Posted By: Rackscha
visual:
cameras are not rendered on a entity texture. entity renders a special color into the buffer for a screenshader to replace these pixels with the camera

the camera needs to keep an eye on the player and stay on the same line as the portal. so it moves along it.

and it is required to translate a relative point from one portal to another. which means making a position relative to a portal, rotating it back, then rotating it by the other portal and making it absolut again. Sabe goes for rotations


Hi Dico!

Unfortunately, screen you've posted doesn't show up :<
About shaders and what Rackscha said, I guess using shaders will be faster plus it does that 'cut-off' effect. I've done it differently (cause I'm not familiar with shaders) and just rendered view directly on the texture of the portal model (and I guess this is one of the worst ways to do this). Anyway, I'm still stuck and breaking my brain on how to add player's position/angles into the portal view, so it does look like a whole into the other room (f.e.) not like a flat TV.

Best regards!
Posted By: Dico

Re: "linked portal door" - 01/14/16 20:49

Haha this is my problem too , but with right angles and position
Originally Posted By: 3run
like a flat TV.


this is another image link : http://i.imgur.com/3CJkwwE.jpg
Posted By: 3run

Re: "linked portal door" - 01/14/16 20:53

Now I see it. Well one of my main problem is, that I can't pick right words for search for those calculation things. I'm pretty sure there are some kind of a tutorials with basic calculations/algorithms etc.

Best regards!
Posted By: Dico

Re: "linked portal door" - 01/14/16 21:11

I get the idea from this video : https://www.youtube.com/watch?v=51BSdESAMwM
so you can calcule the portal cam movement from player cam view.
Posted By: Reconnoiter

Re: "linked portal door" - 01/14/16 21:18

Maybe this will help (note: these links will take you to our nemesis, you have been warned tongue ):

http://answers.unity3d.com/questions/39509/portal-2-how-to-make-a-portal-in-unity-3d.html
http://answers.unity3d.com/questions/455799/is-it-posable-to-make-a-gun-shoot-a-portal.html

Quote:
add player's position/angles into the portal view, so it does look like a whole into the other room (f.e.) not like a flat TV.
, the answer here is probably shaders. You may also try changing the VIEW's arc to 'warp' your flatscreen TV (perhaps also try aspect).

PS: just some random silly idea that popped up in my head, perhaps create a dummy entity for that you see in the portal but render it behind your player.
Posted By: 3run

Re: "linked portal door" - 01/14/16 21:22

Originally Posted By: Dico
I get the idea from this video : https://www.youtube.com/watch?v=51BSdESAMwM
so you can calcule the portal cam movement from player cam view.
Nice video, it shows exactly what I'm trying to come up with instead of current 'flat' views grin

Originally Posted By: Reconnoiter
Ohhh noooo, my eyes shocked
Originally Posted By: Reconnoiter
Quote:
add player's position/angles into the portal view, so it does look like a whole into the other room (f.e.) not like a flat TV.
, the answer here is probably shaders. You may also try changing the VIEW's arc to 'warp' your flatscreen TV (perhaps also try aspect).
Changing arc etc won't really help in my situation (sure they will need to be tweaked at the end, but the problem is that I need to add camera's positions/angles on the top of the view positions/angles (the view, which is rendered on the texture of the portal). At least this is what I think I need to do, but I just can't get the math part smirk


Best regards!
Posted By: Reconnoiter

Re: "linked portal door" - 01/14/16 21:35

Can't your rotate the portal's VIEW with the player's camera? Perhaps deforming/changing its shape so it doesn't look like you rotate the VIEW with the player? (just a wild quess)

ps: doesn't unreal 1 (not UT 1, but unreal) has also 'real' portals? Not does it matter much, but perhaps it can give you ideas.
Posted By: 3run

Re: "linked portal door" - 01/14/16 21:42

Originally Posted By: Reconnoiter
Can't your rotate the portal's VIEW with the player's camera? Perhaps deforming/changing its shape so it doesn't look like you rotate the VIEW with the player? (just a wild quess)
Sure you can, and I guess that's the key to sucsess grin But the problem is, that simply moving/rotating it won't help. I need some kind of algorithm which will calculate all those rotations/movement stuff automatically. F.e. Uhrwerk said this about rotation:
Quote:
target portal view angle = camera.angle + (see through portal angle - target portal angle)
And I got it to work somehow, but without movement only rotation looks really weird (or maybe it just doesn't work correctly grin ).


Originally Posted By: Reconnoiter
ps: doesn't unreal 1 (not UT 1, but unreal) has also 'real' portals? Not does it matter much, but perhaps it can give you ideas.
Originally Posted By: 3run
Anyway, I found a nice video demostraiting what I want to archive:
World Portals - What's the big deal?
Take a look at this. As the video describtion says:
Quote:
Duke Nukem 3D supported non-euclidean geometry, in 1996.
Maybe Unreal had same non-euclidean geometry support, I don't know unfortunately. Tomorrow I'll make a small research probably, it's too late right now here at my place.


Edit: Here is what I've made so far right now (code is dirty and too many comments I know, just ignore them grin ):
Download link
Posted By: txesmi

Re: "linked portal door" - 01/14/16 22:01

Hi,
I can imagine the way but never did it.

It needs portals as two different models. One looking to +X axe and the other to -X axe, so both models share their orientation in reference to the wall. First portal is placed looking in front of the wall and the second looking to the wall.

It needs three cameras, one for player and one for each portal. All same render target size and arc. Portal cameras are placed by computing offsets from portals to player, rotating them by portals inverse orientations (in order to get the offsets in object space of each portal), rotating them again by opposite portals orientations and adding opposite portals positions. The process is same for orientations but with angles, you know. As Wjbender stated, portal cameras need a clipping plane to be set so polygons behind portals are not drawn. Look at cameras PORTALCLIP flag, no mysteries. Portal cameras have to be rendered before player camera.

The shader of portals has to calculate the screen space coords of vertex inside vertex shader and sample the render target of their linked camera on pixel shader. I can't find the algorithm right now but it is very simple.

edited___________
Code:
outTex = outPos.xy / outPos.z;


if I am not wrong...
Posted By: Wjbender

Re: "linked portal door" - 01/15/16 07:24

I found an example on unity for the view angles , I am sure someone here can translate the math .

http://answers.unity3d.com/questions/992289/portal-effect-using-render-textures-how-should-i-m.html
Posted By: Reconnoiter

Re: "linked portal door" - 01/15/16 14:09

Originally Posted By: 3run
Originally Posted By: 3run
Anyway, I found a nice video demostraiting what I want to archive:
World Portals - What's the big deal?
Take a look at this. As the video describtion says:
Quote:
Duke Nukem 3D supported non-euclidean geometry, in 1996.
Maybe Unreal had same non-euclidean geometry support, I don't know unfortunately. Tomorrow I'll make a small research probably, it's too late right now here at my place.
, didn't know that about DukeN3d (pretty cool), but the Unreal 1 I mean was like a real Portal portal/teleport. It could be my nostaligia blinding me a bit, but iirc you could really look through it (like a real view /not like flat tv) and also fire projectiles etc. through it. I remember seeing it in only 1 map, which looks similar to UT 1's Codex. My brother also remembers how well it looked so I know atleast it was not a dream. grin He even remembered reading something like that they changed the portals/teleports for UT 1 cause the Unreal 1 were to heavy on the computer. (dont quote me on that though)

Edit: found it I think http://s37.photobucket.com/user/BrainStorm_wow/media/UT3/tele.jpg.html

Also perhaps read this (although it seems to be more about using the ut3 editor) -> https://forums.epicgames.com/threads/717287-How-do-you-make-Classic-Unreal-Tournament-teleporters
Posted By: 3run

Re: "linked portal door" - 01/15/16 14:18

Thank you very much guys, that will be an interesting read!

Reconnoiter@ that screen looks pretty great! it's really increadible to hear, that they've done this back in 1998.

I found this on the forum so far, it seems that making portals were in vogue back in 2007 grin
Portal Madness [Demo]
Portal Tech 2

And I even found a shader made by XxXGuitar511:
Code:
texture mtlSkin1;
float4x4 matWorldViewProj;
float4x4 matWorldView;
float fAlpha;

sampler imageTex = sampler_state
{
	Texture = <mtlSkin1>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;   
	AddressU  = wrap;
	AddressV  = wrap;
};

struct vIn
{
	float4 Pos : POSITION;
};

struct vOut
{
	float4 Pos : POSITION;
	float3 Tex : TEXCOORD0;
};

struct pIn
{
	float3 Tex : TEXCOORD0;
};

vOut pVS (vIn In)
{
	vOut Out = (vOut)0;
	Out.Pos = mul(In.Pos, matWorldViewProj);
	Out.Tex = mul(In.Pos, matWorldView).xyz;
	//
	return(Out);
}

float4 pPS (pIn In) : COLOR
{
	float2 tPos = In.Tex.xy/In.Tex.z;
	//
	tPos.y = 1 - (tPos.y*1.135 + 0.5);
	tPos.x = tPos.x*0.855 + 0.5;
	//
	float4 color = tex2D(imageTex, tPos);
	color.a *= fAlpha;
	//
	return(color);
}

technique portalView
{
	pass one
	{
		VertexShader = compile vs_1_1 pVS();
		PixelShader = compile ps_2_0 pPS();
	}
}

But I don't have any use for it yet. I'm still researching!



Edit: there were even some threads with open sources for portals, but all links are dead grin
OPEN SOURCE PROJECT - REAL TIME PORTALS
Portal Madness... WIP

Edit2: I guess I found some tips over the net:
Quote:
Render your portal space scene with same camera orientation, but camera position shifted by the same vector that describes the camera's offset from the portal in local space.


Edit3: I found a 'little' but in my code, I'm passing same positions/angles for source and destination portals to updateView function. To fix that just change the following line:
Code:
updateView(portalEnt[i].portalView, portalEnt[i].linkedEnt.x, portalEnt[j].ownerEnt.x, portalEnt[i].linkedEnt.pan, portalEnt[j].ownerEnt.pan);

TO:
Code:
updateView(portalEnt[i].portalView, portalEnt[i].linkedEnt.x, portalEnt[i].ownerEnt.x, portalEnt[i].linkedEnt.pan, portalEnt[i].ownerEnt.pan);

Plus I found a good tutorial:
Tom's Programming Blog
And I'm trying to get the matrix calculations from it correctly working in my project.
Posted By: 3run

Re: "linked portal door" - 01/15/16 21:05

After reading several article and unsucsessfuly trying to convert the calculation from the Tom's Blog (it works, but independently from portal angles, so if you rotate destination or source portal, everything get's **** up), I tried to create something by myself. Thank to those article, I somehow got the main idea of what I needed to do, so I came up with a small demo (only math calculations, no reflation and fancy stuff yet).

HERE IS THE SOURCE (just save it and run from SED):
Code:
ENTITY* heroEnt;
ENTITY* ghost1Ent;

ENTITY* portal1Ent;
ENTITY* portal2Ent;

void calculatePortal(ENTITY* ent, VECTOR* srcPos, VECTOR* dstPos, ANGLE* srcAng, ANGLE* dstAng){
	
	if(!heroEnt){ return; }
	
	ANGLE tempAng;
	vec_fill(tempAng.pan, 0);
	
	VECTOR tempPos;	
	vec_fill(tempPos.x, 0);
	
	ang_diff(tempAng.pan, dstAng.pan, srcAng.pan);
	vec_set(tempPos.x, srcPos.x);
	vec_sub(tempPos.x, heroEnt.x);
	vec_rotate(tempPos.x, tempAng.pan);
	// vec_inverse(tempPos.x); // uncomment this to mirror player's position at destination portal (comment ang_rotate 180 bellow!)
	vec_add(tempPos.x, dstPos.x);
	
	
	ANGLE temp2Ang, endAng;
	vec_fill(temp2Ang.pan, 0);
	vec_fill(endAng.pan, 0);
	
	ang_diff(temp2Ang.pan, srcAng.pan, heroEnt.pan);
	vec_inverse(temp2Ang.pan);
	ang_rotate(temp2Ang.pan, vector(180, 0, 0));
	vec_set(endAng.pan, dstAng.pan);
	ang_add(endAng.pan, temp2Ang.pan);
	
	
	// if player far away from us:
	if(vec_dist(heroEnt.x, ent.x) > 25){
		if(!is(ent.parent, INVISIBLE)){
			set(ent.parent, INVISIBLE);
		}
	}
	else{
		if(is(ent.parent, INVISIBLE)){
			reset(ent.parent, INVISIBLE);
		}
		
		vec_set(ent.parent.x, tempPos.x);
		vec_set(ent.parent.pan, endAng.pan);
		
		VECTOR tempVec;
		vec_fill(tempVec.x, 0);
		
		vec_set(tempVec.x, vector(2.5, 0, 0));
		vec_rotate(tempVec.x, ent.parent.pan);
		vec_add(tempVec.x, ent.parent.x);
		draw_point3d(tempVec.x, COLOR_RED, 100, 1);
	}
}

void portal1(){
	VECTOR tempVec;
	vec_fill(tempVec.x, 0);
	
	portal1Ent = my;
	
	vec_set(my.scale_x, vector(0.05, 1, 1));
	my.pan += random(360);
	set(my, LIGHT | UNLIT | PASSABLE);
	vec_set(my.blue, COLOR_RED);
	
	my.parent = ent_create(CUBE_MDL, my.x, NULL);
	vec_set(my.parent.scale_x, vector(0.25, 0.25, 0.25));
	set(my.parent, TRANSLUCENT | LIGHT | UNLIT | PASSABLE);
	vec_set(my.parent.blue, COLOR_RED);
	
	while(!portal2Ent){ wait(1); }
	
	while(1){
		
		my.pan += 5 * (key_cul - key_cur) * time_step;
		
		my.x += 5 * (key_t - key_g) * time_step;
		my.y += 5 * (key_f - key_h) * time_step;
		
		vec_set(tempVec.x, vector(5, 0, 0));
		vec_rotate(tempVec.x, my.pan);
		vec_add(tempVec.x, my.x);
		draw_line3d(tempVec.x, NULL, 100); 
		draw_line3d(tempVec.x, COLOR_RED, 100); 
		draw_line3d(my.x, COLOR_RED, 100); 
		draw_point3d(tempVec.x, COLOR_RED, 100, 1);
		
		calculatePortal(my, my.x, portal2Ent.x, my.pan, portal2Ent.pan);
		
		wait(1);
	}
}


void portal2(){
	VECTOR tempVec;
	vec_fill(tempVec.x, 0);
	
	portal2Ent = my;
	
	vec_set(my.scale_x, vector(0.05, 1, 1));
	my.pan += random(360);
	set(my, LIGHT | UNLIT | PASSABLE);
	vec_set(my.blue, COLOR_GREEN);
	
	my.parent = ent_create(CUBE_MDL, my.x, NULL);
	vec_set(my.parent.scale_x, vector(0.25, 0.25, 0.25));
	set(my.parent, TRANSLUCENT | LIGHT | UNLIT | PASSABLE);
	vec_set(my.parent.blue, COLOR_GREEN);
	
	while(!portal1Ent){ wait(1); }
	
	while(1){
		
		my.pan += 5 * (key_cuu - key_cud) * time_step;
		
		my.x += 5 * (key_i - key_k) * time_step;
		my.y += 5 * (key_j - key_l) * time_step;
		
		vec_set(tempVec.x, vector(5, 0, 0));
		vec_rotate(tempVec.x, my.pan);
		vec_add(tempVec.x, my.x);
		draw_line3d(tempVec.x, NULL, 100); 
		draw_line3d(tempVec.x, COLOR_GREEN, 100); 
		draw_line3d(my.x, COLOR_GREEN, 100); 
		draw_point3d(tempVec.x, COLOR_GREEN, 100, 1);
		
		calculatePortal(my, my.x, portal1Ent.x, my.pan, portal1Ent.pan);
		
		wait(1);
	}
}


void main(){
	
	fps_max = 60;
	level_load("");
	
	random_seed(0);
	
	// create portals:	
	ent_create(CUBE_MDL, vector(-25, 25, 0), portal1);	
	ent_create(CUBE_MDL, vector(25, -25, 0), portal2);
	
	VECTOR tempVec;
	vec_fill(tempVec.x, 0);
	
	heroEnt = ent_create(CUBE_MDL, nullvector, NULL);
	vec_set(heroEnt.scale_x, vector(0.25, 0.25, 0.25));
	set(heroEnt, TRANSLUCENT | LIGHT | UNLIT);
	vec_set(heroEnt.blue, COLOR_WHITE);
	c_setminmax(heroEnt);	
	
	sun_light = 0;
	set(camera, ISOMETRIC);
	camera.arc = 10;
	camera.z = 100;
	camera.tilt = -90;
	
	while(1){
		
		DEBUG_VAR(heroEnt.pan, 210);
		DEBUG_VAR(portal1Ent.pan, 250);
		DEBUG_VAR(portal2Ent.pan, 270);
		
		heroEnt.skill1 = 5 * (key_w - key_s) * time_step;
		heroEnt.skill2 = 5 * (key_a - key_d) * time_step;
		heroEnt.pan += 5 * (key_z - key_x) * time_step;
		c_move(heroEnt, nullvector, heroEnt.skill1, IGNORE_PASSABLE | GLIDE);
		
		vec_set(tempVec.x, vector(2.5, 0, 0));
		vec_rotate(tempVec.x, heroEnt.pan);
		vec_add(tempVec.x, heroEnt.x);
		draw_point3d(tempVec.x, COLOR_RED, 100, 1);
		
		draw_text("green and red cubes are 'ghost' players position in the destination portals\nwhite cube is player, and those two red/green lines are portals\nyou can see the way they are facing from the lines comming out of portals\nthe green one is source portal and the other one is destination portal (and visa versa)\nuse cursor keys to rotate the portals use WSAD to move the player around \nand TGFH and IKJL to move portals", 10, 10, COLOR_WHITE);
		
		wait(1);
	}
}

Please give it a try guys and tell me, am I even on the right track?

Edit: I think, this will at least help me with object duplication, to get the seamless transition of object from one portal to another.

Edit2: I edited the code (updated).

Best regards!
Posted By: Dico

Re: "linked portal door" - 01/16/16 01:00

Originally Posted By: 3run
After reading several article and unsucsessfuly trying to convert the calculation from the Tom's Blog (it works, but independently from portal angles, so if you rotate destination or source portal, everything get's **** up), I tried to create something by myself. Thank to those article, I somehow got the main idea of what I needed to do, so I came up with a small demo (only math calculations, no reflation and fancy stuff yet).

HERE IS THE SOURCE (just save it and run from SED):
Code:
ENTITY* heroEnt;
ENTITY* ghost1Ent;

ENTITY* portal1Ent;
ENTITY* portal2Ent;

void calculatePortal(ENTITY* ent, VECTOR* srcPos, VECTOR* dstPos, ANGLE* srcAng, ANGLE* dstAng){
	
	if(!heroEnt){ return; }
	
	ANGLE tempAng;
	vec_fill(tempAng.pan, 0);
	
	VECTOR tempPos;	
	vec_fill(tempPos.x, 0);
	
	ang_diff(tempAng.pan, dstAng.pan, srcAng.pan);
	vec_diff(tempPos.x, srcPos.x, heroEnt.x);
	vec_rotate(tempPos.x, tempAng.pan);
	vec_inverse(tempPos.x);
	vec_add(tempPos.x, dstPos.x);
	
	
	ANGLE temp2Ang, endAng;
	vec_fill(temp2Ang.pan, 0);
	vec_fill(endAng.pan, 0);
	
	ang_diff(temp2Ang.pan, srcAng.pan, heroEnt.pan);
	vec_set(endAng.pan, dstAng.pan);
	vec_inverse(temp2Ang.pan);
	ang_add(endAng.pan, temp2Ang.pan);
	
	
	// if player far away from us:
	if(vec_dist(heroEnt.x, ent.x) > 25){
		if(!is(ent.parent, INVISIBLE)){
			set(ent.parent, INVISIBLE);
		}
	}
	else{
		if(is(ent.parent, INVISIBLE)){
			reset(ent.parent, INVISIBLE);
		}
		vec_set(ent.parent.x, tempPos.x);
		vec_set(ent.parent.pan, endAng.pan);
	}
}

void portal1(){
	VECTOR tempVec;
	vec_fill(tempVec.x, 0);
	
	portal1Ent = my;
	
	vec_set(my.scale_x, vector(0.05, 1, 1));
	my.pan += random(360);
	set(my, LIGHT | UNLIT | PASSABLE);
	vec_set(my.blue, COLOR_RED);
	
	my.parent = ent_create(CUBE_MDL, my.x, NULL);
	vec_set(my.parent.scale_x, vector(0.25, 0.25, 0.25));
	set(my.parent, TRANSLUCENT | LIGHT | UNLIT | PASSABLE);
	vec_set(my.parent.blue, COLOR_RED);
	
	while(!portal2Ent){ wait(1); }
	
	while(1){
		
		my.pan += 5 * (key_cul - key_cur) * time_step;
		
		my.x += 5 * (key_t - key_g) * time_step;
		my.y += 5 * (key_f - key_h) * time_step;
		
		vec_set(tempVec.x, vector(5, 0, 0));
		vec_rotate(tempVec.x, my.pan);
		vec_add(tempVec.x, my.x);
		draw_line3d(tempVec.x, NULL, 100); 
		draw_line3d(tempVec.x, COLOR_RED, 100); 
		draw_line3d(my.x, COLOR_RED, 100); 
		draw_point3d(tempVec.x, COLOR_RED, 100, 1);
		
		calculatePortal(my, my.x, portal2Ent.x, my.pan, portal2Ent.pan);
		
		wait(1);
	}
}


void portal2(){
	VECTOR tempVec;
	vec_fill(tempVec.x, 0);
	
	portal2Ent = my;
	
	vec_set(my.scale_x, vector(0.05, 1, 1));
	my.pan += random(360);
	set(my, LIGHT | UNLIT | PASSABLE);
	vec_set(my.blue, COLOR_GREEN);
	
	my.parent = ent_create(CUBE_MDL, my.x, NULL);
	vec_set(my.parent.scale_x, vector(0.25, 0.25, 0.25));
	set(my.parent, TRANSLUCENT | LIGHT | UNLIT | PASSABLE);
	vec_set(my.parent.blue, COLOR_GREEN);
	
	while(!portal1Ent){ wait(1); }
	
	while(1){
		
		my.pan += 5 * (key_cuu - key_cud) * time_step;
		
		my.x += 5 * (key_i - key_k) * time_step;
		my.y += 5 * (key_j - key_l) * time_step;
		
		vec_set(tempVec.x, vector(5, 0, 0));
		vec_rotate(tempVec.x, my.pan);
		vec_add(tempVec.x, my.x);
		draw_line3d(tempVec.x, NULL, 100); 
		draw_line3d(tempVec.x, COLOR_GREEN, 100); 
		draw_line3d(my.x, COLOR_GREEN, 100); 
		draw_point3d(tempVec.x, COLOR_GREEN, 100, 1);
		
		calculatePortal(my, my.x, portal1Ent.x, my.pan, portal1Ent.pan);
		
		wait(1);
	}
}


void main(){
	
	fps_max = 60;
	level_load("");
	
	random_seed(0);
	
	// create portals:	
	ent_create(CUBE_MDL, vector(-25, 25, 0), portal1);	
	ent_create(CUBE_MDL, vector(25, -25, 0), portal2);
	
	heroEnt = ent_create(CUBE_MDL, nullvector, NULL);
	vec_set(heroEnt.scale_x, vector(0.25, 0.25, 0.25));
	set(heroEnt, TRANSLUCENT | LIGHT | UNLIT);
	vec_set(heroEnt.blue, COLOR_WHITE);
	c_setminmax(heroEnt);	
	
	sun_light = 0;
	set(camera, ISOMETRIC);
	camera.arc = 10;
	camera.z = 100;
	camera.tilt = -90;
	
	while(1){
		
		DEBUG_VAR(heroEnt.pan, 210);
		DEBUG_VAR(portal1Ent.pan, 250);
		DEBUG_VAR(portal2Ent.pan, 270);
		
		heroEnt.skill1 = 5 * (key_w - key_s) * time_step;
		heroEnt.skill2 = 5 * (key_a - key_d) * time_step;
		heroEnt.pan += 5 * (key_z - key_x) * time_step;
		c_move(heroEnt, nullvector, heroEnt.skill1, IGNORE_PASSABLE | GLIDE);
		
		draw_text("green and red cubes are 'ghost' players position in the destination portals\nwhite cube is player, and those two white lines are portals\nyou can see the way they are facing from the lines comming out of portals\nthe one near by the player is source portal and the other\none is destination portal, use cursor keys to rotate the portals\nuse WSAD to move the player around and TGFH and IKJL to move portals", 10, 10, COLOR_WHITE);
		
		wait(1);
	}
}

Please give it a try guys and tell me, am I even on the right track?

Edit: I think, this will at least help me with object duplication, to get the seamless transition of object from one portal to another.

Best regards!


Thats cool , im also have a solution for portal view rendring so it not look like a flat tv ,i will upload the source here.
Posted By: Dico

Re: "linked portal door" - 01/16/16 01:56

ok guys this is what i do for now , so i use the shader from gs sdk for water mirror : http://www.mediafire.com/download/zsgdj8difxeqrej/portal.rar
this source need adapting for teleporting.
Posted By: 3run

Re: "linked portal door" - 01/16/16 06:52

Dico@ thank you very much! your demo got me the main idea of the calculations! now I'll try to make an algorithm for it laugh

Best regards!
Posted By: Dico

Re: "linked portal door" - 01/16/16 11:14

3run@ I'm very happy to help in this project laugh
Posted By: txesmi

Re: "linked portal door" - 01/17/16 10:00

Hi,
I gived a try to this issue. I was pretty sure I was right when sentenced how portal camera offset and orientation should be computed but failed frown

Code:
ANGLE angBack;
vec_set ( &angBack, &entPortalA->pan );
vec_inverse ( &angBack );

vec_diff ( &camPortalA->x, &camera->x, &entPortalA->x );
vec_rotate ( &camPortalA->x, &angBack ); 
vec_rotate ( &camPortalA->x, &entPortalB->pan );
vec_add ( &camPortalA->x, &entPortalB->x );

vec_set ( &camPortalA->pan, &camera->pan );
ang_add ( &camPortalA->pan, &angBack );
ang_add ( &camPortalA->pan, &entPortalB->pan );



This what I got so far: download
Move portals by right and left mouse buttons.

Vertical portals, portal cameras clipping planes, and portals shader work good at least xP
Posted By: 3run

Re: "linked portal door" - 01/17/16 18:32

Originally Posted By: txesmi
Vertical portals, portal cameras clipping planes, and portals shader work good at least xP
Thank you very much! laugh I just got home after the week end, so I'll continue on copulating with my poor brain grin

My best regards!
Posted By: Dico

Re: "linked portal door" - 01/17/16 23:42

Originally Posted By: txesmi
Hi,
I gived a try to this issue. I was pretty sure I was right when sentenced how portal camera offset and orientation should be computed but failed frown

Code:
ANGLE angBack;
vec_set ( &angBack, &entPortalA->pan );
vec_inverse ( &angBack );

vec_diff ( &camPortalA->x, &camera->x, &entPortalA->x );
vec_rotate ( &camPortalA->x, &angBack ); 
vec_rotate ( &camPortalA->x, &entPortalB->pan );
vec_add ( &camPortalA->x, &entPortalB->x );

vec_set ( &camPortalA->pan, &camera->pan );
ang_add ( &camPortalA->pan, &angBack );
ang_add ( &camPortalA->pan, &entPortalB->pan );



This what I got so far: download
Move portals by right and left mouse buttons.

Vertical portals, portal cameras clipping planes, and portals shader work good at least xP


Good exemple , thanks laugh
Posted By: 3run

Re: "linked portal door" - 01/19/16 12:21

I'm playing (editing calculations) with the example that txesmi made and it looks quiet interesting, but my brain already hurts grin
Quote:
PortalB:
PortalA:
It looks like I'm on the right track (at least I hope so)!

Best regards
Posted By: 3run

Re: "linked portal door" - 01/19/16 16:30

A LITTLE UPDATE!

I've done transitions, and they seems to work great (at least for vertical portals), but I can't get visuals to work correct yet. As soon as I'll get visual to run fine, I'll upload a demo! laugh


Best regards
Posted By: alibaba

Re: "linked portal door" - 01/19/16 16:32

This is my progress so far. A really interesting topic here!
https://www.youtube.com/watch?v=akKEjwQz460

IŽll try to finish it!
Posted By: 3run

Re: "linked portal door" - 01/19/16 16:34

It looks great! laugh Keep it up Alibaba!

Best regards!
© 2024 lite-C Forums