0 registered members (),
1,459
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
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: Hawthourne]
#447181
11/23/14 08:28
11/23/14 08:28
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
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: Hawthourne]
#447199
11/23/14 16:51
11/23/14 16:51
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
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:
// 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
|
|
|
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
Serious User
|
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:
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.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|