Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 827 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
[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 Offline OP
Serious User
Reconnoiter  Offline 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?

Code:
//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

M
Malice
Unregistered
Malice
Unregistered
M



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 Offline OP
Serious User
Reconnoiter  Offline 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);

Code:
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

M
Malice
Unregistered
Malice
Unregistered
M



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.

Code:
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 Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
What the heck, this compensation code works crazy grin (got to it through trial and error, check it with different resolutions):

Code:
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

M
Malice
Unregistered
Malice
Unregistered
M



If it works then good. I am sorry not to supply more support , but I don't even have the engine installed anymore.

Code:
// 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: ] #456639
12/02/15 10:56
12/02/15 10:56
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Oops sry I said "check it with different resolutions" but I meant "(I) checked it with different resolutions".

But I just double checked it and it isn't entirely perfect but it seems to be fine for now, with only big offset with weird ratio's where e.g. y reso is bigger than x reso.

ty for the replies

Re: vec_to_screen with the view as bmap on panel [Re: Reconnoiter] #456644
12/02/15 16:01
12/02/15 16:01
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
Hi,
Since the view is at x0:y0 (otherway it will not be rendered correctly over the render target) you only need to add the panel position to the result of vec_to_screen. No more calculations are needed. vec_to_screen takes into account view position and size already.

Salud!




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 Offline OP
Serious User
Reconnoiter  Offline 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)

Code:
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 Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
sure

Code:
#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
Page 1 of 2 1 2

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