Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 863 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Fitting entity to the screen, based size (in pixel) #479365
03/24/20 07:35
03/24/20 07:35
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Hi everyone!

As some of you know, i'm working on wallpaper project. Now i need some help.

I have to use an entity as a wallpaper, instead of "panel" or "view entity". Because I have to use shader effects, especially post process. I use the vec_to_screen function to fit the wallpaper on the screen like this;

[Linked Image]

But this way causes some problems. Is there an easier way to do this? I want to fit wallpaper on the screen without moving the object in the x direction.

You can download and take a look the sample from here.


Thanks in advance!

Re: Fitting entity to the screen, based size (in pixel) [Re: Emre] #479366
03/24/20 08:42
03/24/20 08:42
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
There should be a way using, fov, screensize and entity size, but not exactly sure how.
Did you try view entities or bmap_process with panels though?


3333333333
Re: Fitting entity to the screen, based size (in pixel) [Re: Quad] #479367
03/24/20 08:49
03/24/20 08:49
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Originally Posted by Quad
There should be a way using, fov, screensize and entity size, but not exactly sure how.
Did you try view entities or bmap_process with panels though?

Hi Quad. Unfortunately, i'm still using A7. A7 doesn't support bmap_process. Even if it so still i have to use world entity for post process effects. Panels and view entities are not affected by post processing shaders.

Re: Fitting entity to the screen, based size (in pixel) [Re: Emre] #479368
03/24/20 09:38
03/24/20 09:38
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
I think I may have the solution. First, setting the ISOMETRIC flag is mandatory I think, since you're working with flat surfaces such that the x position causes no problems. Then we need a fixed camera arc which I calculated* to roughly 53. With this arc, the screen dimensions are as big as the entity/picture dimensions. Lastly we just calculate the new scale directly. I commented the needed lines.



*The actual calculation can be found in the manual (under "arc") with the formula: width = view.size_x * 2 * tan(view.arc/2).
If we calculate the arc with that, we get an exact solution of 53.130102354156.

Code
///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////

ENTITY* slayt_ent;

#define image_type skill1
#define landscape 1
#define portrait 0

action slayt_ent_act()
{
	my.ambient=100;
	wait(1); //wait for the morphing
	var scale;
	var width = my.max_y * 2; //the actual width and height
	var height = my.max_z * 2;
	while(1)
	{
		if(width > screen_size.x)  //depending on what needs to fit into the screen
			scale = screen_size.x/width;
		if(height > screen_size.y)
			scale = screen_size.y/height;
		vec_fill(my.scale_x,scale);		
		wait(1);
	}
}


int level=0;
function level_load_sample()
{
	if(level==0)//landscape sample
	{
		if(slayt_ent!=NULL)
		{
			ent_remove(slayt_ent);
		}
		slayt_ent=ent_create("slaytent.png",vector(100,0,0),slayt_ent_act);//create slayt_entity (slaytent.png)
		ent_morph(slayt_ent,"wall_landscape.jpg");// change wallpaper
		slayt_ent.image_type=landscape;
		level=1;
		return;
	}
	if(level==1)// portrait sample
	{
		if(slayt_ent!=NULL)
		{
			ent_remove(slayt_ent);
		}
		slayt_ent=ent_create("slaytent.png",vector(100,0,0),slayt_ent_act);//create slayt_entity (slaytent.png)
		ent_morph(slayt_ent,"wall_portrait.jpg");// change wallpaper
		slayt_ent.image_type=portrait; 
		level=0;
		return;
	}
}

function main()
{
	fps_max=75;
	video_mode=9;
	video_screen=2;
	wait(3);
	level_load("");
	set(camera,ISOMETRIC); //needed to have a flat projection
	camera.arc = 53; //the estimated arc for the same height/screensize dimension
	
	level_load_sample();
	on_enter= level_load_sample;
	
	while(1)
	{
		draw_text("Press Enter to change wallpaper",screen_size.x-500,20,COLOR_RED);
		wait(1);
	}
}


Last edited by alibaba; 03/24/20 10:08.

Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: Fitting entity to the screen, based size (in pixel) [Re: alibaba] #479369
03/24/20 10:09
03/24/20 10:09
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Wow! Works like a charm! Thank you so much, alibaba!

Re: Fitting entity to the screen, based size (in pixel) [Re: Emre] #479370
03/24/20 10:58
03/24/20 10:58
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
You're welcome! Glad to have been of help.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: Fitting entity to the screen, based size (in pixel) [Re: Emre] #479371
03/24/20 12:53
03/24/20 12:53
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
I would suggest using the camera's top, botton, left, and right members for a full control of the isometric projection.

Other different way would be computing the projection of the quad directly in clip space into the vertex shader. Starting with a fullscreen square (-1:-1/1:1), it only needs to be multiplied by the proportions. Something like this:
Code
outPos.xy = inPos.xy * vImageSize.xy / vViewportSize.xy;
outPos.xy += 2.0f * vOffset.xy / vViewportSize.xy;
outPos.z = 0.5f; // depth into the view fustrum 0<->1
outPos.w = 1.0f;

Re: Fitting entity to the screen, based size (in pixel) [Re: Emre] #479373
03/24/20 13:59
03/24/20 13:59
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Got it! Thank you!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1