0 registered members (),
1,459
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
[SOLVED] vec_to_screen with the view as bmap on panel
#456593
11/30/15 12:45
11/30/15 12:45
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Hi, I have trouble with converting the 3d pos of an object to the 2d pos for draw_text. The text is not drawn direct at the object but instead is drawn with an offset. Is that cause I show the VIEW on a panel bmap which is smaller than the VIEW's size?
//do only once
small_view.bmap = bmap_createblack(450, 450, 24);
...
objectview_panel.bmap = small_view.bmap; //to show it ontop of the interface
vec_set(draw_vec, ent_obj.x);
vec_to_screen(draw_vec, small_view); // to screen coordinates
str_for_num(draw_str, ent_obj.HEALTH);
draw_text(draw_str, draw_vec.x, draw_vec.y, vector(255, 255, 255));
For solution see end page 1 / page 2
Last edited by Reconnoiter; 12/03/15 12:25.
|
|
|
Re: vec_to_screen with the view as bmap on panel
[Re: Reconnoiter]
#456603
11/30/15 18:32
11/30/15 18:32
|
Malice
Unregistered
|
Malice
Unregistered
|
The function does the calculation based on the clipping Frustum(Whatever the hell that word is).
So yes, you should be able to line it up, by adjusting the draw vec by the offset of the view-panel size. Figure out the xy difference ex 25%x25% then you can vec_scale or vec_normalize(draw_vec,0.75); before the call to draw_text Edit - The above would only work if you target bmap is anchored at pos [0,0]. Otherwise it will take more to adjust the text. Basically I would assume the engine sets VIEW pos [0,0] x VEIW size. So to adjust you have to offset by the difference of targetmap pos and size.
Last edited by Malice; 12/01/15 04:10.
|
|
|
Re: vec_to_screen with the view as bmap on panel
[Re: ]
#456620
12/01/15 11:37
12/01/15 11:37
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Thanks it works better, not perfect yet but a big improvement (it still gives to much offset with objects that are more to the north/top or to the south/bottom);
objectview_panel.bmap = small_view.bmap; //to show it ontop of the interface
vec_set(draw_vec, ent_obj.x);
vec_to_screen(draw_vec, small_view); // to screen coordinates
draw_vec.x /= screen_size.x / objectview_panel.size_x;
draw_vec.y /= screen_size.y / objectview_panel.size_y;
draw_vec.x += objectview_panel.pos_x;
draw_vec.y += objectview_panel.pos_y;
str_for_num(draw_str, ent_obj.HEALTH);
draw_text(draw_str, draw_vec.x, draw_vec.y, vector(255, 255, 255));
ps: a bit unrelated to this thread but you really should give yourself more credit, your a smart guy
|
|
|
Re: vec_to_screen with the view as bmap on panel
[Re: Reconnoiter]
#456628
12/01/15 17:49
12/01/15 17:49
|
Malice
Unregistered
|
Malice
Unregistered
|
Well this is one of those places where using a logic fails to a good math solution. Many other users are better at complex math ideas. There are factors I can't know for your post. Camera ISOMETRIC or NOT? VEIW top down? PANEL target same aspect as screen resolution? Also you operate on vec.x/y with math, they are vars, and pixel locations are pure int, there is no x =5.74; This can be cause of some normal offset. And additively and cause a good amount of offset. Here I'd be forced to use one of my very specific, guess and test solutions. Find entity is above or below the accurate zone at bmap center. Plug in a constant as a modifier and adjust it by a modifier.
draw_vec.y+=...........;
// end vec adjustment
if( draw_vec.y < panel.y+(panel_size.y/2)) // above center
{
draw_vec.y(+-)= 5*(a modifier based on dist center-to-top)
}
// invert
if( draw_vec.y > panel.y+(panel_size.y/2)) // below center
{
draw_vec.y(+-)= 5*(a modifier based on dist center-to-top)
}
Mal p.s. Very kind of you.
Last edited by Malice; 12/01/15 17:50.
|
|
|
Re: vec_to_screen with the view as bmap on panel
[Re: ]
#456631
12/01/15 18:48
12/01/15 18:48
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
What the heck, this compensation code works (got to it through trial and error, check it with different resolutions):
draw_vec.x /= screen_size.x / fullscreen_image_pan[0].size_x; //size_x/size_y are both 450
draw_vec.y /= screen_size.x / fullscreen_image_pan[0].size_y; //but screen reso are e.g. 1000x600
draw_vec.x += fullscreen_image_pan[0].pos_x;
draw_vec.y += fullscreen_image_pan[0].pos_y * (screen_size.x/screen_size.y);
Note that for draw_vec.y I am using screen_size .x too. We make a strange team, haha. Info: this VIEW is not isometric, aspect is default (/ not touched), VIEW is top down, panel has same aspect as screen reso I think.
Last edited by Reconnoiter; 12/01/15 18:49.
|
|
|
Re: vec_to_screen with the view as bmap on panel
[Re: Reconnoiter]
#456635
12/02/15 00:06
12/02/15 00:06
|
Malice
Unregistered
|
Malice
Unregistered
|
If it works then good. I am sorry not to supply more support , but I don't even have the engine installed anymore.
// Shrink the draw_vec
vec_mul(draw_vec,vector(fullscreen_image_pan[0].size_x/small_view.size_x,fullscreen_image_pan[0].size_y/small_view.size_y,0));
// find diff of screen pos[0,0] and image corner
vec_set(vec_temp,vec_sub(vector(screen_size.x,screen_size.y,0),vector(fullscreen_image_pan[0].pos_x,fullscreen_image_pan[0].pos_y,0)));
// move shrunk vec to use image corner as if screen pos[0,0]
vec_add(draw_vec,vec_temp);
This is pure guessing, The math or idea might be wrong. But may work. OF COURSE... You have a working solution, just this is just something to play with. IF IT AIN'T BROKEN DON'T FIX IT! EDIT - This has to be broken code as view_size and image_size should be the same based on the manual.. So then the MUL second vec would be view_size_x/screen_size.x --/-- size.y/size.y, with view_size and image_size exchangeable Ok Mal
Last edited by Malice; 12/02/15 00:20.
|
|
|
Re: vec_to_screen with the view as bmap on panel
[Re: txesmi]
#456645
12/02/15 16:06
12/02/15 16:06
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Do you have an example?, for me that doesn't work. (I am probably making some newbie mistake)
vec_set(draw_vec, ent_obj.x);
vec_to_screen(draw_vec, house_largeview); // to screen coordinates
draw_vec.x += my_viewpan.pos_x;
draw_vec.y += my_viewpan.pos_y;
Last edited by Reconnoiter; 12/02/15 16:07.
|
|
|
Re: vec_to_screen with the view as bmap on panel
[Re: Reconnoiter]
#456646
12/02/15 16:11
12/02/15 16:11
|
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
|
sure
#include <acknex.h>
void main ()
{
video_mode = 8;
wait(1);
level_load ( "" );
ENTITY *ent = ent_create ( SPHERE_MDL, nullvector, NULL );
ent->x = 400;
VIEW *cam = view_create ( 1 );
cam->bg = pixel_for_vec ( COLOR_BLACK, 100, 888 );
cam->bmap = bmap_createblack ( 450, 450, 24 );
cam->size_x = 450;
cam->size_y = 450;
cam->flags |= SHOW;
PANEL *pan = pan_create ( "flags=SHOW;", 1 );
pan->bmap = cam->bmap;
pan->pos_x = screen_size.x - 450;
pan->pos_y = screen_size.y - 450;
while ( !key_esc )
{
ent->y = fcos ( total_ticks*5, 100 );
ent->z = fsin ( total_ticks*5, 100 );
VECTOR vec;
vec_set ( &vec, &ent->x );
vec_to_screen ( &vec, cam );
vec.x += pan->pos_x;
vec.y += pan->pos_y;
draw_text ( "X", vec.x, vec.y, COLOR_RED );
wait(1);
}
pan_remove ( pan );
bmap_remove ( cam->bmap );
ptr_remove ( cam );
ent_remove ( ent );
sys_exit ( NULL );
}
Last edited by txesmi; 12/02/15 16:14. Reason: ptr remove instead of view remove xP
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|