Zoom in/out with mikey

Posted By: Siwler

Zoom in/out with mikey - 03/14/12 00:03

Hey guy, asking for some help please?

I'm trying to convert/use this code:
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:
Code:
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
}


Posted By: Uhrwerk

Re: Zoom in/out with mikey - 03/14/12 01:23

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
Code:
camera.arc = clamp(camera.arc,10,120);


where it originally was
Code:
camera.arc = min (max (camera.arc, 10), 120);



Posted By: Siwler

Re: Zoom in/out with mikey - 03/14/12 01:38

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?
Posted By: rojart

Re: Zoom in/out with mikey - 03/14/12 10:26

Please try the code below, maybe this might help.

Code:
#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);
	}
}


Posted By: MasterQ32

Re: Zoom in/out with mikey - 03/14/12 13:04

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:
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);
	}
}


Posted By: Siwler

Re: Zoom in/out with mikey - 03/14/12 20:46

Originally Posted By: rojart
Please try the code below, maybe this might help.

Code:
#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.
© 2024 lite-C Forums