Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
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
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 396 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Noob question about setting orientations. [Re: Hawthourne] #447173
11/21/14 20:15
11/21/14 20:15
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Code:
void main()
{
	level_load("");
	mouse_mode=1;
	
	//after you created the panels you needed
	
	patrolcraft.center_x = patrolcraft.size_x /2;
	patrolcraft.center_y = patrolcraft.size_y /2;
	turret.center_x = turret.size_x /2;
	turret.center_y = turret.size_y /2;
	

	//rotation
	patrolcraft.angle+= (key_q-key_e)*9*time_step;
	
	//rotation
	turret.angle += mouse_force.x;

	//to move forward into the direction of the panel angle
	//you need someone else to help you 
	//but thats one way, you can set the panel.angle 
	//......
}



untested..

observe the usage of time_step ,this is because
you want your movement to act the same on computers with different speeds (frame rate), you can
solidify this time_step increments by setting the max
allowed frames per second through fps_max , usually
as a standard the eye of a human when it comes to
animation perceived by rapid frame changes ,is most
comfortable and easily tricked at 60 frames per second , 60 hz is also a general frequency update for
a computer screen , so it is advisable to set your max_fps=60 somewhere in the first line of your application entry point (the main function) .

another tip , like I said , it is best to stick to integer
values when your dealing with 2d sizes and positions , even though you could step in smaller increments during each frame for movement , ultimately your still dealing with pixels wich cannot have half sized pixels ,for example there is no position 0.5 by 0.5 on a computer screen in terms of pixels , yes ultimately luckily for you the size of the panel is integers also but it is best as I said to stick to integers on sizes and positions in 2d , but you may increase movement by using numbers with values exceeding the decimal , I know multiplication by 0.5 represent half af a number but sizes are integers here luckily for you , the problem however is that you may end up teaching yourself a habbit wich could apply badly to different cases , you are free to ignore this obviously ,just giving my 2cents ..

have fun .

Last edited by Wjbender; 11/21/14 20:47.

Compulsive compiler
Re: Noob question about setting orientations. [Re: Wjbender] #447177
11/22/14 19:17
11/22/14 19:17
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
@Hawthourne, post your code within [code] [/code""] (without the quotes) tags in the future, makes it more clear to read here wink

Also incase you haven't already, AUM http://www.coniserver.net/coni_users/web_users/pirvu/aum/aumonline_e/ may also have some handy code examples for you (about e.g. panels)

Re: Noob question about setting orientations. [Re: Reconnoiter] #447178
11/23/14 04:43
11/23/14 04:43
Joined: Nov 2014
Posts: 24
ME
H
Hawthourne Offline OP
Newbie
Hawthourne  Offline OP
Newbie
H

Joined: Nov 2014
Posts: 24
ME
So thanks for all the neat tips and such. I've been playing with them and see how they can be handy. I've read about the timestep stuff before, but hadn't thought about the integers thing.

However, I still have the same issue as I have had the past few posts. The script editor does not seem to be recognizing the center_x command for either of the panels I am playing with (center_y works fine). I'm not super familiar with computers, but I do recall an earlier issue I had with certain lines not being read. After switching the order of independent strings of code (seemingly irrelevant) it started working but such attempts with this line seem fruitless. Could it be a syntax issue or a bad install of the SED script editor?

Re: Noob question about setting orientations. [Re: Hawthourne] #447179
11/23/14 05:04
11/23/14 05:04
Joined: Nov 2014
Posts: 24
ME
H
Hawthourne Offline OP
Newbie
Hawthourne  Offline OP
Newbie
H

Joined: Nov 2014
Posts: 24
ME
So it seems to me that when I go back to my original plan, changing the angle by setting PatrolCraft.angle = somevalue it does take the center_x into account. vectoangle, on the other hand, ignores the center_x (though it will still take the center_y into account). I'm guessing that this is just a consequence as to how the code is set up and that there isn't any easy fix. Thanks for all of your assistance! My next project is familiarizing myself with entity generation within the script, but there seems to be a lot more material on that so hopefully I won't have to come back here asking more questions about it.

Re: Noob question about setting orientations. [Re: Hawthourne] #447181
11/23/14 08:28
11/23/14 08:28
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
just ignore the integer thingy its irrelevant ..

the vec_to_angle function however works for 3 dimensional entities where a pan tilt and roll are used , the panel.angle however only needs the angle value itself whereas vec_to_angle uses 3 components for
3d Euler angles , this is why I asked you if its a 2d object or a 3d object , there are different ways to deal
with each , axis orientation in 3d space is also different from 2d

don't feel bad about asking help , this is what this forum is for .

Last edited by Wjbender; 11/23/14 14:52.

Compulsive compiler
Re: Noob question about setting orientations. [Re: Wjbender] #447197
11/23/14 15:32
11/23/14 15:32
Joined: Nov 2014
Posts: 24
ME
H
Hawthourne Offline OP
Newbie
Hawthourne  Offline OP
Newbie
H

Joined: Nov 2014
Posts: 24
ME
So is there an analogous function for 2 dimensional projects, like the one I am working on (what I am working on now). The vec_to_angle does work, it jsut doesn't rotate it around the panel's center. Amusingly, it seems that 2D might actually be harder than 3D in some respects, since in 3D levels you have the level editor to work with rather than doing everything in script. Most of the helpful material out there seems geared towards 3D projects as well.

Re: Noob question about setting orientations. [Re: Hawthourne] #447199
11/23/14 16:51
11/23/14 16:51
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
In this example which I've made, you can see how to rotate both, MODEL and PANEL!
Here you go:
Code:
// game function:
void main(){
	// load an empty level:
	level_load("");
	// make sky WHITE:
	vec_set(sky_color.blue, COLOR_WHITE);
	// no sun_light:
	sun_light = 0;
	// rotate camera downwards:
	vec_set(camera.pan, vector(0, -90, 0));
	
	// enable mouse:
	mouse_mode = 4;
	
	// create empty panel:
	PANEL* spaceShip = pan_create("", 1);
	// make it visible:
	set(spaceShip, SHOW);
	// create black bmap for it:
	spaceShip.bmap = bmap_createblack(16, 32, 24);
	// update panels size:
	spaceShip.size_x = bmap_width(spaceShip.bmap);
	spaceShip.size_y = bmap_height(spaceShip.bmap);
	// set rotation center for the panel (right in the middle):
	spaceShip.center_x = spaceShip.size_x * 0.5;
	spaceShip.center_y = spaceShip.size_y * 0.5;
	
	// create cube model:
	you = ent_create(CUBE_MDL, vector(0, 0, -50), NULL);
	// set it's size:
	vec_set(you.scale_x, vector(0.5, 0.25, 0.5));
	// make it change it's color:
	set(you, LIGHT);
	// make it's color GREEN:
	vec_set(you.blue, COLOR_GREEN);
	
	// temporary vector:
	VECTOR tempVec;
	// set all vector members to zero:
	vec_fill(tempVec.x, 0);
	
	// loop:
	while(!key_esc){
		
		// save mouse positions (XY):
		tempVec.x = mouse_pos.x;
		tempVec.y = mouse_pos.y;
		// save cube's Z position (not really needed):
		tempVec.z = you.z;
		
		// convert vector from screen coordinates into the world!
		vec_for_screen(tempVec.x, camera);
		
		// subtract cube's position (so we'll have a direction to rotate at):
		vec_sub(tempVec.x, you.x);
		// rotate cube towards the direction we've calculated above:
		vec_to_angle(you.pan, tempVec.x);
		// cycle cube's PAN angle from 0 to 360:
		you.pan %= 360;
		// don't allow to change it's TILT and ROLL angles:
		you.tilt = you.roll = 0;
		
		// place panel right in the middle of the screen:
		spaceShip.pos_x = (screen_size.x / 2) - (bmap_width(spaceShip.bmap) / 2);
		spaceShip.pos_y = (screen_size.y / 2) - (bmap_height(spaceShip.bmap) / 2);
		
		// set it's pan to the cube's pan:
		spaceShip.angle = you.pan;
		// cycle panel's pan from 0 to 360:
		spaceShip.angle %= 360;
		
		// show panel's angle on screen:
		DEBUG_VAR(spaceShip.angle, 10);
		// show cube's PAN angle on screen:
		DEBUG_VAR(you.pan, 40);
		// show current mouse position as a red quad:
		draw_quad(NULL, vector(mouse_pos.x, mouse_pos.y, 0), NULL, vector(16, 16, 0), NULL, COLOR_RED, 100, 0);
		// wait one frame:
		wait(1);
	}
	// exit application:
	sys_exit("bye!");
}

Please read carefully, and if you have any questions, before asking them here, read manual, it may give you an answer!


Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Noob question about setting orientations. [Re: 3run] #447341
12/05/14 12:32
12/05/14 12:32
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
A bit late to the party, but @Hawthourne, vec_to_angle can be used with 2d coordinates too. But since 2d works with only 2 coordinates, and not 3 like 3d, you need to set the z coordinates of the vector to zero and generally speaking pos_y = x and pos_x = y (see below code to understand what I mean by that). The code below uses mouse_pos as vector for vec_to_angle and so it lets mypanel rotate towards the cursor:

Code:
ANGLE vectoangle_ang;
 VECTOR temp_vec1, temp_vec2; 

 while (1)
 {
  vec_set(temp_vec1, vector(mypanel.pos_y, mypanel.pos_x, 0));
  vec_set(temp_vec2, vector(mouse_pos.y, mouse_pos.x, 0));
  vec_sub(temp_vec2, temp_vec1);	
  vec_to_angle(vectoangle_ang, temp_vec2);
  
  mypanel.center_x = (mypanel.size_x / 2); // set the rotation center at the panel center
  mypanel.center_y = (mypanel.size_y / 2);
  mypanel.angle = integer(vectoangle_ang.pan); //! only pan is usefull here
  
  DEBUG_VAR(vectoangle_ang.pan, 80); //just for testing purposes
  
  wait(1);
 }



I don't know if this great code or whatever, just know it works and its fairly easy to understand & to work with.

Page 2 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