- This wiki is out of date, use the continuation of this wiki instead
Get angle
From FenixWiki
(Difference between revisions)
| Revision as of 11:02, 11 July 2007 (edit) Sandman (Talk | contribs) (→Example) ← Previous diff |
Current revision (11:40, 25 December 2007) (edit) (undo) Sandman (Talk | contribs) m |
||
| (6 intermediate revisions not shown.) | |||
| Line 5: | Line 5: | ||
| '''INT''' get_angle ( <'''INT''' processID> ) | '''INT''' get_angle ( <'''INT''' processID> ) | ||
| - | Returns the [[angle]] between the coordinates of a certain [[process]] and the process calling get_angle(). | + | Returns the [[angle]] between the coordinates of a certain [[process]] and the process calling [[get_angle]](). |
| == Parameters == | == Parameters == | ||
| Line 15: | Line 15: | ||
| '''INT''' : The wanted [[angle]]. | '''INT''' : The wanted [[angle]]. | ||
| {| | {| | ||
| - | | -1 || - An error ''may'' have occurred. | + | | -1 || - An error ''may'' have occurred: invalid [[process]]. |
| |- | |- | ||
| | !-1 || - The wanted [[angle]]. | | !-1 || - The wanted [[angle]]. | ||
| Line 24: | Line 24: | ||
| Program angling; | Program angling; | ||
| Const | Const | ||
| - | screen_width = 320; | + | screen_width = 320; |
| - | screen_height = 200; | + | screen_height = 200; |
| - | screen_depth = 8; | + | screen_depth = 8; |
| + | screen_fps = 60; | ||
| + | screen_frameskip = 0; | ||
| + | Global | ||
| + | int distance; | ||
| + | int tempID; | ||
| Begin | Begin | ||
| // Set the screen mode | // Set the screen mode | ||
| set_mode(screen_width,screen_height,screen_depth); | set_mode(screen_width,screen_height,screen_depth); | ||
| + | set_fps(screen_fps,screen_frameskip); | ||
| - | // Create mouse graph and start | + | // Change this to see what happens |
| + | resolution = 100; | ||
| + | |||
| + | // Create mouse graph and start mousepointer | ||
| x = new_map(20,20,screen_depth); | x = new_map(20,20,screen_depth); | ||
| map_clear(0,x,rgb(255,0,0)); | map_clear(0,x,rgb(255,0,0)); | ||
| Line 45: | Line 54: | ||
| // Set position | // Set position | ||
| - | x = screen_width /2; | + | x = screen_width /2 * resolution; |
| - | y = screen_height/2; | + | y = screen_height/2 * resolution; |
| + | |||
| + | // Display distance | ||
| + | write(0,0,0,0,"Distance:"); | ||
| + | write_int(0,60,0,0,&distance); | ||
| // Always point to the mouse | // Always point to the mouse | ||
| Repeat | Repeat | ||
| - | // Get the angle between this process' coordinates and those of mousegraph. | + | // Get the angle and distance between this process' coordinates and those of mousegraph. |
| - | // and get_id() here, because usually there would only be one mousepointer and one always. | + | // We can use TYPE and get_id() here, because usually there would only be one |
| - | | + | // mousepointer and one always. |
| + | tempID = get_id(type mousepointer); | ||
| + | angle = get_angle(tempID); | ||
| + | distance = get_dist(tempID); | ||
| frame; | frame; | ||
| Until(key(_esc)) | Until(key(_esc)) | ||
| Line 69: | Line 85: | ||
| // the mouse set in this process. Then after that other process can use those coordinates. | // the mouse set in this process. Then after that other process can use those coordinates. | ||
| priority = 1; | priority = 1; | ||
| + | // Obtain father's resolution | ||
| + | resolution = father.resolution; | ||
| + | // Loop | ||
| Loop | Loop | ||
| - | x = mouse.x; | + | // Obtain X and Y coordinates of the mouse and adjust for resolution |
| - | y = mouse.y; | + | // (mouse.y and mouse.y have an unchangeable resolution of 1) |
| + | x = mouse.x * resolution; | ||
| + | y = mouse.y * resolution; | ||
| frame; | frame; | ||
| End | End | ||
| End | End | ||
| </pre> | </pre> | ||
| - | Used in example: [[set_mode]](), [[new_map]](), [[map_clear]](), [[drawing_map]](), [[drawing_color]](), [[draw_line]](), [[mouse]], [[graph]], [[x]], [[y]], [[angle]], [[priority]] | + | Used in example: [[set_mode]](), [[new_map]](), [[map_clear]](), [[drawing_map]](), [[drawing_color]](), [[draw_line]](), [[write]](), [[write_int]](), [[get_id]](), [[get_angle]](), [[get_dist]](), [[resolution]], [[mouse]], [[graph]], [[x]], [[y]], [[angle]], [[priority]] |
| This example could also be done with [[fget_angle]](), which is easier and doesn't require an extra [[process]]. | This example could also be done with [[fget_angle]](), which is easier and doesn't require an extra [[process]]. | ||
| + | |||
| + | It could look something like:<br> | ||
| + | http://wwwhome.cs.utwente.nl/~bergfi/fenix/wiki/get_angle.PNG | ||
| + | |||
| + | {{Funcbox | ||
| + | | category = Processinteraction | ||
| + | }} | ||
Current revision
Contents |
[edit] Definition
INT get_angle ( <INT processID> )
Returns the angle between the coordinates of a certain process and the process calling get_angle().
[edit] Parameters
| INT processID | - The other process. |
[edit] Returns
INT : The wanted angle.
| -1 | - An error may have occurred: invalid process. |
| !-1 | - The wanted angle. |
[edit] Example
Program angling;
Const
screen_width = 320;
screen_height = 200;
screen_depth = 8;
screen_fps = 60;
screen_frameskip = 0;
Global
int distance;
int tempID;
Begin
// Set the screen mode
set_mode(screen_width,screen_height,screen_depth);
set_fps(screen_fps,screen_frameskip);
// Change this to see what happens
resolution = 100;
// Create mouse graph and start mousepointer
x = new_map(20,20,screen_depth);
map_clear(0,x,rgb(255,0,0));
mousepointer(0,x);
// Create arrow, assign to graph
graph = new_map(30,30,screen_depth);
drawing_map(0,graph);
drawing_color(rgb(0,255,0));
draw_line( 0,29,29,30/2);
draw_line( 0, 0,30,30/2);
// Set position
x = screen_width /2 * resolution;
y = screen_height/2 * resolution;
// Display distance
write(0,0,0,0,"Distance:");
write_int(0,60,0,0,&distance);
// Always point to the mouse
Repeat
// Get the angle and distance between this process' coordinates and those of mousegraph.
// We can use TYPE and get_id() here, because usually there would only be one
// mousepointer and one always.
tempID = get_id(type mousepointer);
angle = get_angle(tempID);
distance = get_dist(tempID);
frame;
Until(key(_esc))
End
/**
* Follows the mouse coordinates. x is always mouse.x and y is always mouse.y
* for processes with priority <1. The graphic of this process will be a certain graphic.
* int file - The fileID of the file where the graphic is located
* int graph - The graphID of the graphic to be used for this process
*/
Process mousepointer(int file,int graph)
Begin
// Set the priority to 1, because we first want to have the correct coordinates of
// the mouse set in this process. Then after that other process can use those coordinates.
priority = 1;
// Obtain father's resolution
resolution = father.resolution;
// Loop
Loop
// Obtain X and Y coordinates of the mouse and adjust for resolution
// (mouse.y and mouse.y have an unchangeable resolution of 1)
x = mouse.x * resolution;
y = mouse.y * resolution;
frame;
End
End
Used in example: set_mode(), new_map(), map_clear(), drawing_map(), drawing_color(), draw_line(), write(), write_int(), get_id(), get_angle(), get_dist(), resolution, mouse, graph, x, y, angle, priority
This example could also be done with fget_angle(), which is easier and doesn't require an extra process.
It could look something like:
| Processinteraction Functions | |
| • Advance() • Collision() • Exists() • Get_angle() • Get_dist() • Get_id() • Let_me_alone() • Signal() • Xadvance() • | |
