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
1 registered members (AndrewAMD), 533 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Joystick programing #472681
05/14/18 00:43
05/14/18 00:43
Joined: May 2018
Posts: 7
L
LaserJock2000 Offline OP
Newbie
LaserJock2000  Offline OP
Newbie
L

Joined: May 2018
Posts: 7
I want to use a "ThrustMaster T.Flight HOTAS X" joystick to control my movements. The Lite-C tutorial/manual covers the basics of x & y movement but not using the rotation of the joystick. I can find no examples of how to use joy_rot nor an axis map of how to use all 6 axis that should be available. Can you please help? Any more detailed resources on-line or books that go deeper into Lite-C?

Thanks
Dave

Re: Joystick programing [Re: LaserJock2000] #472686
05/14/18 09:09
05/14/18 09:09
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Give this a try (paste into a new *.c file and start it in SED):
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

// joyNum 1/2, buttonNum 1-32
int joy_pressed(int joyNum, int buttonNum)
{
	var bitmask = joy_buttons;
	if(joyNum == 2) bitmask = joy2_buttons;

	if(buttonNum <= 10) return !!((bitmask<<10) & (1 << buttonNum-1));
	return !!(bitmask & (1 << buttonNum-11));
}

// joyNum 1/2, axisNum 1-6
var joy_axis(int joyNum, int axisNum)
{
	VECTOR *source[2];
	
	if(axisNum < 1 || axisNum > 6) return 0;
	if(joyNum == 2)
	{
		source[0] = &joy2_raw;
		source[1] = &joy2_rot;
	}
	else
	{
		source[0] = &joy_raw;
		source[1] = &joy_rot;
	}
	axisNum--;
	var *pv = source[axisNum/3];
	return pv[axisNum%3]; // read var at x,y,z
}

// joyNum 1/2
int joy_dpad(int joyNum)
{
	if(joyNum == 2) return joy2_hat;
	return joy_hat;
}

void main()
{
	fps_max = 60;
	video_mode = 9;
	
	while(1)
	{
		draw_text(str_printf(NULL,"num_joysticks: %d",(int)num_joysticks),20,20,COLOR_RED);
		int i,j;
		for(j = 1; j <= 2; j++)
		{
				draw_text(str_printf(NULL,"Joy%d-DPad: %d",j,(int)joy_dpad(j)),200*j,20,COLOR_RED);
			for(i = 1; i <= 6; i++)
			{
				draw_text(str_printf(NULL,"Joy%d-Axis%d: %d",j,i,(int)joy_axis(j,i)),200*j,40+20*i,COLOR_RED);
			}
			for(i = 1; i <= 32; i++)
			{
				draw_text(str_printf(NULL,"Joy%d-Button%d: %d",j,i,(int)joy_pressed(j,i)),200*j,180+20*i,COLOR_RED);
			}
		}
		
		wait(1);
	}
}



Check the values on screen when you move the joystick or push buttons, then use the corresponding axes in your script (copy the helper functions).
For example:

Code:
camera.pan += joy_axis(1, 1)*0.1*time_step;
camera.pan = ang(camera.pan);
my.pan = camera.pan; // assuming a first person camera
camera.tilt -= joy_axis(1, 2)*0.1*time_step; // might need to be "+" as well instead of "-"
camera.tilt = clamp(camera.tilt,-85,85);



"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Joystick programing [Re: LaserJock2000] #472697
05/15/18 01:29
05/15/18 01:29
Joined: May 2018
Posts: 7
L
LaserJock2000 Offline OP
Newbie
LaserJock2000  Offline OP
Newbie
L

Joined: May 2018
Posts: 7
Thanks! This works. I will now spend some time understanding the details.

Are there any good references for Lite-C? The on-line tutorial and manual leave much to be desired in terms of detail and depth.

Thank you very much.

Dave

Re: Joystick programing [Re: LaserJock2000] #472700
05/15/18 05:40
05/15/18 05:40
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
joy_pressed and joy_axis could be written in a more legible way. For example as follows:

Code:
// joyNum 1/2, axisNum 1-6
var joy_axis(int joyNum, int axisNum)
{
	if(joyNum == 2)
	{
		switch(axisNum)
		{
			case 1:
			return joy2_raw.x;

			case 2:
			return joy2_raw.y;

			case 3:
			return joy2_raw.z;

			case 4:
			return joy2_rot.x;
			
			case 5:
			return joy2_rot.y;

			case 6:
			return joy2_rot.z;

			default:
			return 0;
		}
	}
	// you can put this in an else case but as the function returns in the case above either way you don't need to
	// joyNum == 1 (or other (invalid) values)
	switch(axisNum)
	{
		case 1:
		return joy_raw.x;

		case 2:
		return joy_raw.y;

		case 3:
		return joy_raw.z;

		case 4:
		return joy_rot.x;
		
		case 5:
		return joy_rot.y;

		case 6:
		return joy_rot.z;
	}
	
	return 0;
}


Alternatively you could for example still use the "source" pointer array approach in my original post and then use a switch case statement (instead of the var *pv stuff).


The manual for lite-C is pretty good actually. I use the offline manual (open SED -> press F1) in "Index" mode usually - you will need to know most commands already for that (the Index approach) though.

What are you missing, speaking of detail and depth? Details about the functions themselves or more general concepts (how to write a movement/ enemy code/ menu code)?

Btw. there's a thing called the acknex user magazine, including small game samples (with a focus on the code, not the artwork): http://www.opserver.de/coni_users/web_users/pirvu/aum/aumonline_e/index.html


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Joystick programing [Re: Superku] #472708
05/15/18 12:02
05/15/18 12:02
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
if you know what a pointer is, you might sort all those var addresses into an array.

Code:
var *joyAxe[2][6];

void joyAxe_startup () {
	joyAxe[0][0] = &joy_raw.x;
	joyAxe[0][1] = &joy_raw.y;
	joyAxe[0][2] = &joy_raw.z;
	joyAxe[0][3] = &joy_rot.x;
	joyAxe[0][4] = &joy_rot.y;
	joyAxe[0][5] = &joy_rot.z;
	joyAxe[1][0] = &joy2_raw.x;
	joyAxe[1][1] = &joy2_raw.y;
	joyAxe[1][2] = &joy2_raw.z;
	joyAxe[1][3] = &joy2_rot.x;
	joyAxe[1][4] = &joy2_rot.y;
	joyAxe[1][5] = &joy2_rot.z;
}
...
vMove.x = *joyAxe[0][1] * nSpeed * time_step;


Re: Joystick programing [Re: txesmi] #472877
05/27/18 18:06
05/27/18 18:06
Joined: May 2018
Posts: 7
L
LaserJock2000 Offline OP
Newbie
LaserJock2000  Offline OP
Newbie
L

Joined: May 2018
Posts: 7
Thanks. Got the joystick working.

New question: My car goes through the walls of the arena that I made in WED. How do I make the walls impassible while using the Physics package?

And, again using the Physics package, how do I make the car respond to the joystick in a relative steering mode vice absolute?

Thanks
Dave


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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