Jump to content
  • Advertisement

scragglypoo

Member
  • Content Count

    22
  • Joined

  • Last visited

Community Reputation

114 Neutral

1 Follower

About scragglypoo

  • Rank
    Member

Personal Information

  • Interests
    Art

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hello, I have a big old project that cannot be converted from D3D_XYZRHW to D3D_XYZ. The problem is whatever polygons around me distort, but everything in the distance is good. It seems to happen when NDC space vertex.x <= 0. I guess clipping must be the solution; but I don't know how. Here is my current code. VERTEX_DECL LocalToScreen( const Vector& vector ) { VERTEX_DECL vertex; vertex.xyz = vector - Game::Eye; vertex.xyz = Game::CameraOrientation * Game::ProjectionMatrix * vertex.xyz; vertex.xyz.x = vertex.xyz.x / vertex.xyz.z; vertex.xyz.y = vertex.xyz.y / vertex.xyz.z; vertex.xyz.z = 1.0 / vertex.xyz.z; // This stops polygons around camera distorting; but it fully removes them which // is not a proper solution. I think I need some kind of clamping. if ( vertex.z <= 0.0 ) { return vertex; } vertex.xyz.x = vertex.xyz.x * Game::HalfViewportWidth + Game::HalfViewportWidth; vertex.xyz.y = vertex.xyz.y * -Game::HalfViewportHeight + Game::HalfViewportHeight; vertex.rhw = vertex.xyz.z; vertex.xyz.z = vertex.xyz.z * 0.000588; // Legacy. This doesn't seem to do anything. return vertex; }
  2. scragglypoo

    Emulate FAST tripple buffering in Direct3d9

    I expect double-buffering from vsync where it just blocks. The code acts exactly as its supposed to. That's why i want a solution to the normal broken design. I want true tripler-buffering vsync, where it doesn't block but copies to another buffer, so I retain high fps. For example Windows 10 via DWM borderless fullscreen has tripler buffering vsync with high fps, but its still not as fast as true triple buffering would be in exclusive mode.
  3. scragglypoo

    Emulate FAST tripple buffering in Direct3d9

    Present is blocking 10x longer than if it were in immediate mode. D3DPRESENT_DONOTWAIT flag doesnt work either. It isn't jittery, just latency by present blocking. Default render target and swap chain.
  4. Hi, How can I emulate triple buffering in Direct3d9, so I can have vsync with high fps. DWM does it in window mode; why has nobody done it in fullscreen mode?
  5. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    But he does say: Rotate around a local axis: rotation = rotation * Quaternion.AngleAxis(10, Vector3.Up); Rotate around a world axis: rotation = Quaternion.AngleAxis(10, Vector3.Up) * rotation; And it does work for me exactly as your code does (I have to inverse the order however; probably because they're matrices or because I use row order). But I find your code clearer, and ready to use with an angle. Edit: I understand now; rotating around local x-axis, and then world y-axis actually mimics real life, if you move your head.
  6. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    Here is where I read it; maybe it applies to only quaternions https://forum.unity3d.com/threads/understanding-rotations-in-local-and-world-space-quaternions.153330/ Thanks! I got your code working here: Matrix Rotate( Matrix rotation ) { // Rotate around local x-axis. auto x = RotationAboutAxis( this.right, -rotation.Pitch() ); this = this * x; // Rotate around world y-axis. auto y = RotationAboutAxis( Vector::Up, rotation.Yaw() ); this = this * y; return this; } Does it matter what order I put the rotations in? It works either way this*x or this*y first. Also why does y need to be a world-space rotation? why not x?
  7. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    Can you post code for rotationAboutAxis() I can't seem to find any code or figure it out. As for local space and world space, I have read a * b is world space, but b * a is local space so that you don't need to create axis angles? // Rotate around local axis of x. matrix = x * matrix; // Rotate around world axis of y. matrix = matrix * y;
  8. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    me is basically just the camera; SetAngles basically sets euler angles this runs in https://repl.it/languages/CPP // Example program #include <iostream> #include <string> #include <cmath> #include <cstdio> //#define M_PI 3.14159265358979323846F #define M_DEG (180.0F / M_PI) #define M_RAD (M_PI / 180.0F) struct Vector { float x = 0.0; float y = 0.0; float z = 0.0; }; class Quaternion { public : void CreateFromEuler( float pitch, float yaw, float roll ) { double t0 = std::cos( yaw * 0.5 ); double t1 = std::sin( yaw * 0.5 ); double t2 = std::cos( roll * 0.5 ); double t3 = std::sin( roll * 0.5 ); double t4 = std::cos( pitch * 0.5 ); double t5 = std::sin( pitch * 0.5 ); w = t0 * t2 * t4 + t1 * t3 * t5; x = t0 * t3 * t4 - t1 * t2 * t5; y = t0 * t2 * t5 + t1 * t3 * t4; z = t1 * t2 * t4 - t0 * t3 * t5; } Vector GetEuler() { double ysqr = y * y; // roll (x-axis rotation) double t0 = +2.0 * (w * x + y * z); double t1 = +1.0 - 2.0 * (x * x + ysqr); auto roll = std::atan2( t0, t1 ); // pitch (y-axis rotation) double t2 = +2.0 * (w * y - z * x); t2 = ((t2 > 1.0) ? 1.0 : t2); t2 = ((t2 < -1.0) ? -1.0 : t2); auto pitch = std::asin( t2 ); // yaw (z-axis rotation) double t3 = +2.0 * (w * z + x * y); double t4 = +1.0 - 2.0 * (ysqr + z * z); auto yaw = std::atan2( t3, t4 ); return Vector { pitch, yaw, roll }; } Quaternion operator *( const Quaternion &q ) { Quaternion r; r.w = w*q.w - x*q.x - y*q.y - z*q.z; r.x = w*q.x + x*q.w + y*q.z - z*q.y; r.y = w*q.y + y*q.w + z*q.x - x*q.z; r.z = w*q.z + z*q.w + x*q.y - y*q.x; return r; } float x = 0.0; float y = 0.0; float z = 0.0; float w = 1.0; }; int main() { // How much we rotate? auto pitch = 0.0; auto yaw = 45.0; Quaternion a; // Extract euler angles from a matrix. Reading stored euler angles will work too. //a.CreateFromEuler( camera.orient.Pitch(), camera.orient.Yaw(), 0.0 ); auto start_pitch = 35.21; auto start_yaw = 181.58; a.CreateFromEuler( start_pitch * M_RAD, start_yaw * M_RAD, 0.0 ); std::printf( "Orientation a [x: %.2f, y: %.2f, z: %.2f]\n", start_pitch, start_yaw, 0.0 ); Quaternion b; b.CreateFromEuler( pitch * M_RAD, yaw * M_RAD, 0.0 ); std::printf( "Orientation b [x: %.2f, y: %.2f, z: %.2f]\n", pitch, yaw, 0.0 ); auto result = a * b; auto angles = result.GetEuler(); //camera.SetEulerAngles( angles ); std::printf( "Orientation result [x: %.2f, y: %.2f, z: %.2f]\n", angles.x * M_DEG, angles.y * M_DEG, angles.z * M_DEG ); }
  9. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    Code is from here: https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles Edit: Code is down a post
  10. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    Quaternion A angles [x: 35.21, y: 181.58, 0.0] Apply rotation using quaternion B [x:0.0, y: 45.0, 0.0] New angles quaternion C [x: 24.06, y: -127.67, <code doesn't print roll>] Why is it not rotating properly? It is decreasing the pitch, the yaw is working. i can create a quaternion at any x y angle, and then read back fine. But problems happen when I multiply/rotate sometimes. Still the only fix I have is this: Matrix operator * ( Matrix rhs ) { auto x = CreateRotation( rhs.Pitch(), 0.0, 0.0 ); auto y = CreateRotation( 0.0, rhs.Yaw(), 0.0 ); return x * this * y; // return rhs * this; doesnt work! }
  11. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    Reversing a very old game. I can try to show what I can figure out. eye = me.position; rotationProjectionMatrix = me.rotation; // This is not standard vector multiplication? // Note: It uses a vector instead of a matrix for projection. rotationProjectionMatrix.right *= projectionVector.x; rotationProjectionMatrix.up *= projectionVector.y; rotationProjectionMatrix.look *= projectionVector.z; // Projection: screen = mesh.position - eye; screen *= rotationProjectionMatrix; // screen = local_position * rotation * projection;
  12. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    If I reverse the order, pitch rotations are correct, but then yaw rotations decrease the pitch to 0 If I reverse order again, yaw rotations work again, but the pitch rolls if I turned 90deg left I can make a weird fix by doing this: it works for either operand order as well. But why? Matrix operator * ( const Matrix& rotation ) { auto x = CreateRotation( rotation.Pitch(), 0.0, 0.0 ); auto y = CreateRotation( 0.0, rotation.Yaw(), 0.0 ); return x * (*this) * y; }
  13. scragglypoo

    Rotation matrix multiplication causes Gimbal lock

    I have to use matrices to store the rotation me.orientation = (Quaternion( me.rotation ) * CreateQuaternion( 5.0, 0.0, 0.0 )).toMatrix(); i tried this code and i get the same result How do I convert 5 degrees pitch to a non-euler method?
  14. me.rotation = me.rotation * CreateRotation( 5.0, 0.0, 0.0 ); If i spawn and run this code, pitch increases But if i spawn and turn 90deg left and run this code, it rolls How do i fix this? Edit: I use a standard rotation matrix formula from wikipedia
  15. scragglypoo

    Scale world geometry with an aspect ratio?

    The edge distortion
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!