// Zusammengesetzt aus mehreren Beispielen... Cube = Scene Display List( 1 ); Cube << Begin( QUAD_STRIP ); Cube << Color( 1.0, 0.0, 1.0 ); Cube << Vertex( -0.5, 0.5, 0.5 ); Cube << Color( 1.0, 0.0, 0.0 ); Cube << Vertex( -0.5, -0.5, 0.5 ); Cube << Color( 1.0, 1.0, 1.0 ); Cube << Vertex( 0.5, 0.5, 0.5 ); Cube << Color( 1.0, 1.0, 0.0 ); Cube << Vertex( 0.5, -0.5, 0.5 ); Cube << Color( 0.0, 1.0, 1.0 ); Würfel << Eckpunkt(0.5, 0.5, -0.5); Würfel << Farbe(0.0, 1.0, 0.0); Würfel << Eckpunkt(0.5, -0.5, -0.5); Würfel << Farbe(0.0, 0.0, 1.0); Würfel << Eckpunkt(-0.5, 0.5, -0.5); Würfel << Farbe(0.0, 0.0, 0.0); Würfel << Eckpunkt(-0.5, -0.5, -0.5); Würfel << Farbe(1.0, 0.0, 1.0); Würfel << Eckpunkt(-0.5, 0.5, 0.5); Würfel << Farbe(1.0, 0.0, 0.0); Cube << Vertex( -0.5, -0.5, 0.5 ); Cube << End(); cube1 = Scene Display List(); cube1 << arcball( cube, .5 ); // Die Arcballs werden nicht neu erstellt, daher cube2 = Scene Display List(); cube2 << arcball( cube, .5 ); // Sie behalten ihre Positionen. WindowHeight = 600; WindowWidth = 800; mouseOriginY = WindowHeight / 2; mouseOriginX = WindowWidth / 2; mode = "done"; dx = dy = .; mouseMatrix = Identity( 4 ); // <<<< Dies summiert alle Winkel-/Größen-/Skalierungsänderungen // Diese Funktion wird aufgerufen mit m==1 beim Klicken mit der Maus, m==2 beim Ziehen mit der Maus und m=3 beim Loslassen der Maus (k ist der Status von Shift/Strg/Alt) // Diese Funktion gibt absichtlich 0 oder 1 zurück, damit Bogenkugeln ausgeführt werden können oder dieser Code die Mausmatrix anpassen kann. Click2d = Function( {x, y, m, k}, {xt, xs, xr, yr, zr, degrees, radians, dx, dy}, If( m == 1, mouseOriginX = x; mouseOriginY = y; If( Is Shift Key(), mode = "translate" ); // if(Is Alt Key(), // Linux/VirtualBox erreicht die Alt-Taste nie JMP // mode = "rotate"; // ); If( Is Control Key(), mode = "scale" ); If( Is Control Key() & Is Shift Key(), mode = "rotate" ); If( !Is Control Key() & !Is Shift Key(), Return( 0 ); // Erlaube dem Kreisel, die Kontrolle zu übernehmen. 0 bedeutet, dass dieser Handler den Klick NICHT verarbeitet hat. );// , /*else if */ m == 2, dx = x - mouseOriginX; dy = y - mouseOriginY; If( mode == "translate", xt = Identity( 4 ); xt[1, 4] = dx / WindowWidth; xt[2, 4] = -dy / WindowWidth; mouseMatrix = xt * mouseMatrix;// , /* else if */ mode == "scale", xs = Identity( 4 ); xs[1, 1] = If( dx >= 0, (dx + WindowWidth) / WindowWidth// , WindowWidth / (WindowWidth - dx) ); xs[2, 2] = If( dy >= 0, WindowHeight / (dy + WindowHeight)// , (WindowHeight - dy) / WindowHeight ); mouseMatrix = xs * mouseMatrix;// , /* else if */ mode == "rotate", radians = 6 * dy / WindowWidth; xr = Identity( 4 ); // Beginne mit einer Einheitsmatrix und setze dann die Werte ein, um um die x-Achse zu rotieren. xr[2, 2] = Cos( radians ); xr[2, 3] = -Sin( radians ); xr[3, 2] = Sin( radians ); xr[3, 3] = Cos( radians ); yr = Identity( 4 ); // und die y-Achse. radians = 6 * dx / WindowHeight; yr[1, 1] = Cos( radians ); yr[1, 3] = Sin( radians ); yr[3, 1] = -Sin( radians ); yr[3, 3] = Cos( radians ); zr = Identity( 4 ); // und die z-Achse. mouseMatrix = xr * mouseMatrix; mouseMatrix = yr * mouseMatrix; ); mouseOriginX = x; mouseOriginY = y; rebuild();// , /*else if */ m == 3, mode = "done"; 0;// , /* else */ Throw( "unexpected m=" || Char( m ) ) ); //0 // Da diese Funktion NICHT 1 zurückgibt, ruft JMP sie erst beim nächsten Mausklick erneut auf. Ziehvorgänge verhalten sich wie Bewegungen und führen zur Funktion Move2d. 1; // Da sie *1* zurückgibt, ist m=1,2,3 für Drücken,Bewegen,Loslassen ); Scene = Scene Box( WindowWidth, WindowHeight, Click2d ); Scene << Show ArcBall( "Always" ); New Window( "Matrixrotationen", V List Box( Text Box( "Shift-Ziehen: Verschieben\!nStrg-Ziehen: Zoomen\!nStrg-Shift-Ziehen: Drehen\!nVanilla-Ziehen: Würfel drehen" ), Scene ) ); rebuild = Function( {}, degrees = 45; radians = 3.14159 * degrees / 180; // sin und cos verwenden Radiant Scene << clear; Scene << perspective( 45, 3, 7 ); Scene << Translate( 0.0, 0.0, -4.5 ); // Globale Translation/Rotation/Skalierung anwenden Scene << MultMatrix( mouseMatrix ); Scene << pushmatrix; xt = Identity( 4 ); // Um 0,75 nach links verschieben xt[1, 4] = -.75; Scene << MultMatrix( xt ); Scene << callList( Cube1 ); Scene << popmatrix; Scene << pushmatrix; Scene << translate( .75, 0, 0 ); // Um 0,75 nach rechts verschieben Scene << calllist( Cube2 ); Scene << popmatrix; Scene << update; ); rebuild();