Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (NnamueN, Akow, 1 invisible), 1,421 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
vec_for_screen... [solved - nothing interesting in here] #287812
09/02/09 15:54
09/02/09 15:54
Joined: Jul 2009
Posts: 36
S
SomebodyNew Offline OP
Newbie
SomebodyNew  Offline OP
Newbie
S

Joined: Jul 2009
Posts: 36
Good evening everyone,

I want to create an entity that is always at the same position (in world_coordinates) that the mouse cursor (in mouse coords of course) is at (only x and y coords, z-coords don't matter). In order to do that one needs to convert the mouse position to world coordinates (vec_for_screen), so that the engine knows where to place the model.

Here is the code:
Code:
function mouse_item()
{
	MouseItem = me;
	set(my, PASSABLE);
	var ex;
	var ey;
	var ez;
        while(1)
	{
		ex = mouse_pos.x;
		ey = mouse_pos.y;
		ez = 0;
		vec_for_screen(vector(ex, ey, ez), camera);
	  	ent_create("ring.bmp",vector(ex,ey,ez), ring);
		wait(1);
	}
}



The code constantly creates small rings at the calculated coordinates so that one can see where exactly vec_for_screen points to.

Now here is my problem. The code behaves really strange.
First of all the rings are not created at the mouse_cursor's position but with a offset (x and y offset).
Second, they are created at positions inverted to the mouse's movement.
And third, moving the view does not affect where the rings are created (the view is fixed on top of the player and you can move the player around thus changing the view's position).

There are a quiet some threads about vec_for_screen and vec_to_screen... but really, I don't see what went wrong in the above script.

To avoid this problem I measured the window's size in pixels, calculated the zero-vector (resolution / 2, not really but works) or the middle of the screen and then calculated the vector from there to the mouse. Now one can use the angle from 0,0 to mouse x,y... but that is not really a solution since it creates a whole bunch of other problems.
c_trace works too... but that too is what you would call a "dirty trick" I guess.

Sorry if I overlooked something in the manual or just wrote a bad syntax.

Thanks for taking a look at it!

Last edited by SomebodyNew; 09/02/09 21:13.
Re: vec_for_screen... mouse_pos... [Re: SomebodyNew] #287817
09/02/09 16:07
09/02/09 16:07
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
Don't create Vars in an while loop. Because now it creates three vars every frame.


Hilf mir, dir zu helfen!
Re: vec_for_screen... mouse_pos... [Re: hopfel] #287828
09/02/09 17:12
09/02/09 17:12
Joined: Jul 2009
Posts: 36
S
SomebodyNew Offline OP
Newbie
SomebodyNew  Offline OP
Newbie
S

Joined: Jul 2009
Posts: 36
Thanks hopfel, they need to be placed before starting the loop.
This did not change the behavior of the script. I guess it reduces the space reserved for the game.

Re: vec_for_screen... mouse_pos... [Re: SomebodyNew] #287861
09/02/09 21:12
09/02/09 21:12
Joined: Jul 2009
Posts: 36
S
SomebodyNew Offline OP
Newbie
SomebodyNew  Offline OP
Newbie
S

Joined: Jul 2009
Posts: 36
Problem solved.

There was nothing wrong with the code itself. I had the main fill variables with data from other files. I had one pointer not in the right place so the same vector was constantly overriden with two different entries.

Sorry for that. I'll double and triple check my variables & pointers before I'll ask you guys for help the next time.


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