Jump to content

x-alberto

Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by x-alberto

  1. Lightner, too bad I will have to wait until next week before I can put my hands on a reasonable hardware. From a look at your later code example I would say that you do not need to do this: --[CALCULATE VERTICAL FOV IN DEG & RAD] local VFOV_rad = 2 * math.atan( math.tan(HFOV_rad/2) * (sh/sw) ) local VFOV_deg = math.deg(VFOV_rad) From my (otherwise unsupported!) experience it appears that HFOV and VFOV are the same (*), unlsess explicitly set in the rendering options (and, in that case, you should probaly read the value form a dataref instead of deriving it in your code) Again, I may be horribly wrong - I hope I can be more "professional" in my comments when I will be able to run the script. Cheers (*) EDIT - better wording: the linear correction factor needed to compensate for HVOF and VFOV appears to be the same
  2. Hi Lightener, I will not be able to check your code until later this week. From a quick look, are you sure that what you are seeing is really a lag? I would expect the position of your "cursor" to be corrected with roll, which I do not see in your code. (again, that's just an educated guess - I will look at it as soon as possible - I did almost the same in my own plugin and it did seem to work) cheers
  3. Hi I am currently using visual c for win, x-code for mac and gcc for lin. (I definitely see a point in using gizmo instead!) For my ongoing projects the number of transforms per frame is very limited so I will not probably move from my current implementation. In the near future, however, optimisation might matter and, moreover, learning new tricks is cool. I will follow your advice and will post my findings. Ciao Alberto
  4. Hi PhM, thank you for your comments and for the code. I will try to build a function using both your suggestions and the compound rotation matrix. I will investigate using SSE - do I understand corretly that this will require a small ASM fragment? Cheers Alberto
  5. transformed_x,transformed_y,transformed_z = matrix.transform3D( x,y,z, p,r,h ) I agree, one can easily apply the final translation in his own code...
  6. double thumbs up easy to read/access saving the page works as advertised formatting is OK with SRWare Iron browser 10.0.650.0
  7. A sample script demonstrating command rewrite It will create a custom command "SPECIAL/buttons/trim_shift" If you map a key or joy button to this command, it will change the default behavior of standard commands: sim/view_pan_up sim/view_pan_down sim/view_pan_right sim/view_pan_left so that pitch_trim_up pitch_trim_down aileron_trim_left aileron_trim_right will be invoked instead It should work with any aircraft, provided that no other plugin is doing a command rewrite I use this so that my joystick's HAT switch works both to move the view or to trim... Note: there is probably some useless (or bad!) code in it... feedback is welcome --[[ Command rewrite, v 1.0 by x-alberto (www.x-plane.it), 2011 HAT swith remapping to pitch and roll trim (very experimental) If you find Gizmo useful, please make a donation to its author: br@x-plugins.com --]] g_is_shift_trim = 0 g_is_view_up = 0 g_is_view_down = 0 g_is_view_right = 0 g_is_view_left = 0 -- create a custom command for "shifting" xp.newCommand("SPECIAL/buttons/trim_shift", "trim_shift", "trim_shift" ) -- if a command already exists, it apperars that "xp.newCommand" creates a hook instead xp.newCommand("sim/view/pan_up", "View Up", "view_pan_up" ) xp.newCommand("sim/view/pan_down", "View Down", "view_pan_down" ) xp.newCommand("sim/view/pan_left", "View Left", "view_pan_left" ) xp.newCommand("sim/view/pan_right", "View Right", "view_pan_right" ) function main() -- nothing to do here end function OnDraw_Windows() -- nothing to do here as well end -- fun starts here... function trim_shift_OnStart() --button or key press started g_is_shift_trim=1 end function trim_shift_OnHold() --button or key is being held down g_is_shift_trim=2 end function trim_shift_OnStop() --button or key was released g_is_shift_trim=0 end function view_pan_up_OnStart() --button or key press started g_is_view_up=1 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/pitch_trim_up" ) return 1 --prevent x-plane from processing the command end end function view_pan_up_OnHold() --button or key is being held down g_is_view_up=2 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/pitch_trim_up" ) return 1 --prevent x-plane from processing the command end end function view_pan_up_OnStop() --button or key was released g_is_view_up=0 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandEndByName( "sim/flight_controls/pitch_trim_up" ) return 1 --prevent x-plane from processing the command end end function view_pan_down_OnStart() --button or key press started g_is_view_down=1 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/pitch_trim_down" ) return 1 --prevent x-plane from processing the command end end function view_pan_down_OnHold() --button or key is being held down g_is_view_down=2 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/pitch_trim_down" ) return 1 --prevent x-plane from processing the command end end function view_pan_down_OnStop() --button or key was released g_is_view_down=0 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandEndByName( "sim/flight_controls/pitch_trim_down" ) return 1 --prevent x-plane from processing the command end end function view_pan_left_OnStart() --button or key press started g_is_view_left=1 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/aileron_trim_left" ) return 1 --prevent x-plane from processing the command end end function view_pan_left_OnHold() --button or key is being held down g_is_view_left=2 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/aileron_trim_left" ) return 1 --prevent x-plane from processing the command end end function view_pan_left_OnStop() --button or key was released g_is_view_left=0 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandEndByName( "sim/flight_controls/aileron_trim_left" ) return 1 --prevent x-plane from processing the command end end function view_pan_right_OnStart() --button or key press started g_is_view_right=1 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/aileron_trim_right" ) return 1 --prevent x-plane from processing the command end end function view_pan_right_OnHold() --button or key is being held down g_is_view_right=2 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandBeginByName( "sim/flight_controls/aileron_trim_right" ) return 1 --prevent x-plane from processing the command end end function view_pan_right_OnStop() --button or key was released g_is_view_right=0 if g_is_shift_trim == 0 then return 0 --let x-plane process the command else xp.commandEndByName( "sim/flight_controls/aileron_trim_right" ) return 1 --prevent x-plane from processing the command end end
  8. If you prefer a more compact code (possibly less readable), here is the resulting transformation matrix managing the three rotations in one single step: const double Myxz[3][3] = { { cos_H*cos_R + sin_H*sin_P*sin_R, -cos_H*sin_R + sin_H*sin_P*cos_R, sin_H*cos_P}, { cos_P*sin_R, cos_P*cos_R, -sin_P}, {-sin_H*cos_R + cos_H*sin_P*sin_R, sin_H*sin_R + cos_H*sin_P*cos_R, cos_H*cos_P}, };
  9. Hi Nik, you here? Actually Indi's job is (still) a few miles ahead of mine....
  10. Sometimes you need to perform cumbersome math just to to put an object into the right 3D place or, as for my specific case, to get the right relative position of two objects (from two different aircrafts). Suppose you need to know the coordinates of a point of a given aircraft (e.g.because you are actually going to draw an object in that precise point) What you have is the aircraft position (it's geometric center in x-plane local coordinates + heading, roll and pitch) and the offset of your point in aircraft coordinates. what you need is the point position (x,y,z in x-plane local coordinates) Transform3D (code below) will take as input: inLocalCoords: the offest of your object in acf coordinates inMap: the coordinates and angles of the aircraft and will pop out: outCoords: the coordinates of your object in x.plane "local" coordinates (Bottom line: Unless it's already there, this should really go into Gizmo) void Transform3D(const double inLocalCoords[3], /*acf coordinates*/ const double inMap[6], /*x, y, z, heading, pitch, roll (X-Plane has angles in degrees)*/ double outCoords[3]){ //http://en.wikipedia.org/wiki/Rotation_matrix //http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/ArbitraryAxisRotation.html //Make constants easier to handle. //Put angles into radians. const double H_rad = -inMap[3]*DEG2RAD; //heading const double P_rad = inMap[4]*DEG2RAD; //pitch const double R_rad = -inMap[5]*DEG2RAD; //roll const double cos_H = cos(H_rad); const double sin_H = sin(H_rad); const double cos_P = cos(P_rad); const double sin_P = sin(P_rad); const double cos_R = cos(R_rad); const double sin_R = sin(R_rad); //Pitch rotation matrix const double Mx[3][3] = { { 1, 0, 0 }, { 0, cos_P, -sin_P }, { 0, sin_P, cos_P } }; //Heading rotation matrix const double My[3][3] = { { cos_H, 0, sin_H }, { 0, 1, 0 }, { -sin_H, 0, cos_H } }; //Roll rotation matrix const double Mz[3][3] = { { cos_R, -sin_R, 0 }, { sin_R, cos_R, 0 }, { 0, 0, 1 } }; //What we want is out = [Mx*My*Mz] * in //We will use three consequent multiplications //The _only_ correcy sequence is //Mz //Mx //My //otherwise you get garbage (see multiplication rules for matrices...) double step1[3]; double step2[3]; // step1 = Mz * in mmult(inLocalCoords, Mz, step1); // step2 = Mx * step1 mmult(step1, Mx, step2); // out = My * step2 mmult(step2, My, outCoords); /*Finally, apply translation*/ for(int i=0; i<3; i++) outCoords[i]+=inMap[i]; /* X, Y, Z*/ } void mmult(const double inX[3], const double R[3][3], double outX[3]){ for(int n=0; n<3; n++) outX[n]=0; for(int i=0; i<3; i++) for(int j=0; j<3; j++) outX[i] += R[i][j] * inX[j]; } edited: using the code tag a few missing indices just popped out again
  11. I am the one to say thank you... About the code, I haven't yet spent enough time investigating whether the result of any of these calls can be cached across different frames (I call the scissor function once per frame): glGetDoublev (GL_MODELVIEW_MATRIX ,modelM); glGetDoublev (GL_PROJECTION_MATRIX ,projM); glGetIntegerv(GL_VIEWPORT ,viewport); However it appears as if the impact on CPU/FPS is negligible. (remember to release the scissor when done with yuor stuff, or you will trash the screen)
  12. and this is how I do it (thanks to B. Supnik for his advice) in my C projects x,y,w,h are in panel coordinates DefineScissor(double x, double y, double w, double h){ //BEN's advice for SCISSOR GLdouble modelM[16]; // Our current model view matrix GLdouble projM [16]; // Our current projection matrix GLint viewport[4]; // The current viewport glGetDoublev (GL_MODELVIEW_MATRIX ,modelM); glGetDoublev (GL_PROJECTION_MATRIX ,projM); glGetIntegerv(GL_VIEWPORT ,viewport); double x0, y0, z0, x1, y1, z1; gluProject( x, y, 0.0, modelM, projM, viewport, &x0, &y0, &z0); gluProject( w, h, 0.0, modelM, projM, viewport, &x1, &y1, &z1); glScissor(x0, y0, x1, y1); }
×
×
  • Create New...