ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
FAQ Downloads Calendar Search Mark Forums Read

Q&A Using Flexsim and building models

Reply
 
Thread Tools Display Modes
  #1  
Old 05-31-2016
aarias aarias is offline
Flexsim User
 
Join Date: Apr 2008
Posts: 2
Downloads: 9
Uploads: 0
Thanks: 0
Thanked 7 Times in 1 Post
Rep Power: 0
aarias is on a distinguished road
Default Use joystick

I saw in one video to a person using a joystick to navigate in Flexsim, is this possible? How can do thits?

Thanks
Reply With Quote
  #2  
Old 05-31-2016
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1168
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Create a Custom GUI. Drag a "perspective" control into it. Edit the perspective's attributes. Change the >eventfunctions/OnStick code.

The default OnStick code handles 3d-mouse messages. Joysticks also fire the OnStick eventfunction, but you should get their input using the stick() command instead of the param()s.

Then you can adjust the attributes of the perspective view (such as viewpointx, viewpointy, and viewpointradius) based on the input from the joystick.

Code:
treenode view = ownerobject(c);

int type = param(1);
switch (type) {
	case 0: // put your joystick code here:
	{
		view = c; // I think joysticks pass the view as c directly
		// use the stick() to access the inputs from the joystick here
	} break;
	case 1: // translation vector
	{
		double proj = get(viewprojectiontype(view));
		double x = param(2);
		double y = param(3);
		double z = param(4);
		
		// use exponential growth
		x = x*x*x;
		y = y*y*y;
		z = z*z*z;
		
		// calculate the amount to move in the x,y based on view rotation
		double rz = degreestoradians(get(viewpointrz(view)));
		double sine = sin(rz);
		double cosine = cos(rz);
		double dx = y*sine + x*cosine;
		double dy = y*cosine - x*sine;
		
		if (proj == 1) {  // orthographic projection
			double viewmag = get(viewmagnification(view));
			double relax = 0.000005; // to offset the exponential growth
			
			set(viewmagnification(view),(1.0+(max(-9999, z*relax)/10000))*get(viewmagnification(view)));
			
			relax = 0.0000005/get(viewmagnification(view));
			
			inc(viewpointx(view),dx*relax);
			inc(viewpointy(view),-dy*relax);
		} else {  // perspective projection
			double vpradius = get(viewpointradius(view));
			double relax = 0.000000001*fabs(vpradius); // to offset the exponential growth
			
			inc(viewpointx(view),dx*relax);
			inc(viewpointy(view),-dy*relax);
			inc(viewpointradius(view),-z*relax);
			
			if (fabs(vpradius) < 0.0000001) {
				vpradius = sign(vpradius)*0.0000001;
				set(viewpointradius(view),vpradius);
			}
		}
	} break;
	case 2: // rotation vector
	{
		double k3dmouseAngularVelocity = 0.008; // radians per second per count  
		double x = param(2);
		double y = param(3);
		double z = param(4);
		
		inc(viewpointrx(view),x*k3dmouseAngularVelocity);
		//inc(viewpointry(view),-y*k3dmouseAngularVelocity); // helicopter mode: ignore y rotation
		inc(viewpointrz(view),-z*k3dmouseAngularVelocity);
	} break;
	case 3: // buttons
	{
		double buttonvalues = param(2);
		
		#define V3DK_MENU 0x1
		#define V3DK_FIT 0x2
		if (bitwiseand(buttonvalues,V3DK_FIT)) {
			viewmenucommand("View|Zoom...|Reset",view);
		}
	} break;
}

if (!getrunstate()) {
	windowgray(windowfromnode(view),0);
}
Reply With Quote
The Following 3 Users Say Thank You to Phil BoBo For This Useful Post:
arunkrmahadeva (06-01-2016), Carsten Seehafer (06-03-2016), Jing Chen (05-31-2016)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:16 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.