2 registered members (Ayumi, AndrewAMD),
822
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
User
|
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; 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
Senior Expert
|
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
OP
User
|
OP
User
Joined: Jul 2007
Posts: 619
Turkey, Izmir
|
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
Expert
|
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.
///////////////////////////////
#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.
|
|
|
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
Serious User
|
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:
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;
|
|
|
|