ATTENTIONThis 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 |
#2
|
||||
|
||||
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); } |
The Following 3 Users Say Thank You to Phil BoBo For This Useful Post: | ||
Jing Chen (05-31-2016) |