2 registered members (AndrewAMD, SBGuy),
987
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Zoom in/out with mikey
#397063
03/14/12 00:03
03/14/12 00:03
|
Joined: Nov 2009
Posts: 70
Siwler
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2009
Posts: 70
|
Hey guy, asking for some help please? I'm trying to convert/use this code:
starter wheel_zoom()
{
while (1)
{
if (mickey.z > 1)
{
camera.arc += 10 * time; // play with "10"
}
if (mickey.z < -1)
{
camera.arc -= 10 * time; // play with "10"
}
camera.arc = min (max (camera.arc, 10), 120); // limit camera.arc to 10..120
wait (1);
}
}
But I get an error for the min undeclared identifier, so I took that line of code out(camera.arc = min (max (camera.arc, 10), 120);). Now when I zoom it to its max zoom camera.arc resets automatically and scope_pan also resets to hide position. How do I fix this? Here is my converted or just a code that I'm working with light-C:
while (camera.arc > 10) // zoom in until camera.arc is smaller than or equal with 10
{
if (mickey.z > 1)
{
camera.arc += 10 * time_step; // 10 gives the zoom-in speed
}
if (mickey.z < -1)
{
camera.arc -= 10 * time_step;
}
camera.arc = min (max (camera.arc, 10), 120);
wait (1);
}
// the maximum zoom-in factor has been achieved here
camera.pan += (5 - random(10)) * 0.01 * time_step; // time to add fatigue to the mix
camera.tilt += (5 - random(10)) * 0.01 * time_step; // the pan and tilt angles of the camera will change a bit, as if the player was tired, the wind was blowing, etc
}
Honesty will get you far, were dishonesty will get you only so far in life.
|
|
|
Re: Zoom in/out with mikey
[Re: Siwler]
#397065
03/14/12 01:23
03/14/12 01:23
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
min and max were renamed to minv and and maxv. You can either stick to the original code and just replace the renamed funtions or instead use
camera.arc = clamp(camera.arc,10,120);
where it originally was
camera.arc = min (max (camera.arc, 10), 120);
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Zoom in/out with mikey
[Re: Uhrwerk]
#397066
03/14/12 01:38
03/14/12 01:38
|
Joined: Nov 2009
Posts: 70
Siwler
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2009
Posts: 70
|
Thank you, minv and maxv fixed the error but when zoomed in to the maximum zoom, it zooms out all by it self. I don't want it to zoom out unless otherwise.
Do you know how to fix that?
Honesty will get you far, were dishonesty will get you only so far in life.
|
|
|
Re: Zoom in/out with mikey
[Re: Siwler]
#397081
03/14/12 10:26
03/14/12 10:26
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 900
Lgh
|
Please try the code below, maybe this might help.
#include <default.c>
#define PRAGMA_PATH "%EXE_DIR%\samples"
FONT* A20b = "Arial#20b";
function main()
{
level_load("small.hmp");
vec_set(camera.x,vector(-300,0,20));
ent_create(CUBE_MDL, vector(0,0,0), NULL);
PANEL *pInfo = pan_create(NULL,0);
pan_setdigits(pInfo,0,1,5,"FOV = %f", A20b, 1, camera.arc);
pan_setcolor(pInfo,1,1,COLOR_GREEN);
pInfo.pos_x = 5; pInfo.pos_y = 110;
set(pInfo, OUTLINE|SHOW);
def_debug();
camera.arc = 65;
while (1)
{
while (camera.arc > 10)
{
camera.arc = clamp((camera.arc += 10 * mickey.z * time_step/16), 10, 120);
wait (1);
}
while (camera.arc < 11)
{
vec_add(camera.pan, vector((5 - random(10)) * 0.01 * time_step, (5 - random(10)) * 0.01 * time_step, 0));
camera.arc = clamp((camera.arc += 10 * mickey.z * time_step/16), 10, 120);
wait (1);
}
wait(1);
}
}
|
|
|
Re: Zoom in/out with mikey
[Re: rojart]
#397084
03/14/12 13:04
03/14/12 13:04
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
don't use time_step when using mickey! mickey contains the real mouse values (dx, dy, dz or mouse wheel data) also mickey.z is 120 times larger than excepted, so a single tick on the mouse wheel will set mickey.z to 120, not to 1 better code:
function start_mouse_zoom()
{
while(1)
{
// Arc from 10 to 120, mickey.z zo zoom
// Change + to - if it's the wrong direction
// The camera.arc will do 4° steps, so you get some faster zoom than with mickey.z / 120
camera.arc = clamp(camera.arc - mickey.z / 30,10,120);
wait(1);
}
}
|
|
|
Re: Zoom in/out with mikey
[Re: rojart]
#397128
03/14/12 20:46
03/14/12 20:46
|
Joined: Nov 2009
Posts: 70
Siwler
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2009
Posts: 70
|
Please try the code below, maybe this might help.
#include <default.c>
#define PRAGMA_PATH "%EXE_DIR%\samples"
FONT* A20b = "Arial#20b";
function main()
{
level_load("small.hmp");
vec_set(camera.x,vector(-300,0,20));
ent_create(CUBE_MDL, vector(0,0,0), NULL);
PANEL *pInfo = pan_create(NULL,0);
pan_setdigits(pInfo,0,1,5,"FOV = %f", A20b, 1, camera.arc);
pan_setcolor(pInfo,1,1,COLOR_GREEN);
pInfo.pos_x = 5; pInfo.pos_y = 110;
set(pInfo, OUTLINE|SHOW);
def_debug();
camera.arc = 65;
while (1)
{
while (camera.arc > 10)
{
camera.arc = clamp((camera.arc += 10 * mickey.z * time_step/16), 10, 120);
wait (1);
}
while (camera.arc < 11)
{
vec_add(camera.pan, vector((5 - random(10)) * 0.01 * time_step, (5 - random(10)) * 0.01 * time_step, 0));
camera.arc = clamp((camera.arc += 10 * mickey.z * time_step/16), 10, 120);
wait (1);
}
wait(1);
}
}
I like your code example a lot. Gamestusio should include your example code in gamestudio example folder, very nice zoom in and out example.
Honesty will get you far, were dishonesty will get you only so far in life.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|