Results 1 to 7 of 7

Thread: Orthagonal X with perspective Y in OpenGL?

  1. #1

    Orthagonal X with perspective Y in OpenGL?

    Got kind of a wierd situation here, Can it be done? I really only need the X orthagonal since I'm doing my own math for it, but if I could have the Y scaled to Z by OpenGL instead of having to do it myself it would really help.

    Any ideas?

    For those interested, I'm still working on my circlevision strip - compressing 360 degrees of X and 45 degrees of Y into screen width * 1/6th screen height.

    Right now I'm using OpenGL to do this like it was Glide - not a good thing since that drastically underuses OpenGL's capabilities.

    Oh, and if anyone knows a REALLY fast way to calculate Atan and sqrt, I'd love to hear it.
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  2. #2
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Orthagonal X with perspective Y in OpenGL?

    Cant you precalculate the ATan etc?

    [pascal]For I := 1 to 360 do
    MyATanArray[I] := ATan(I);[/pascal]

    Etc?
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  3. #3

    Orthagonal X with perspective Y in OpenGL?

    The famous InvSqrt function:

    [pascal]
    function InvSqrt (x: single): single;
    var xhalf: single;
    i: integer absolute x;
    begin
    xhalf := 0.5*x;
    i := $5f3759df - (i shr 1);
    x := x*(1.5 - xhalf*x*x);
    result := x;
    end;[/pascal]

    Original c source:
    Code:
    float InvSqrt (float x)
    {
        float xhalf = 0.5f*x;
        int i = *(int*)&x;
        i = 0x5f3759df - (i >> 1);
        x = *(float*)&i;
        x = x*(1.5f - xhalf*x*x);
        return x;
    }
    WOO WORD LORD!
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  4. #4

    Orthagonal X with perspective Y in OpenGL?

    Optimized (just last line off)
    [pascal]function InvSqrt (x: single): single;
    var xhalf: single;
    i: integer absolute x;
    begin
    xhalf := 0.5*x;
    i := $5f3759df - (i shr 1);
    result := x*(1.5 - xhalf*x*x);
    end;[/pascal]

  5. #5

    Orthagonal X with perspective Y in OpenGL?

    Very interesting question with the projection...
    I'm not sure how well it will work since I never needed such a wierd projection matrix, but try this:
    Code:
    var
      m: array[0..3, 0..3] of single;
    ...
      glMatrixMode(GL_PROJECTION);
      ZeroMemory(@m, SizeOf(m));
      m[0, 0] := 2;
      m[1, 1] := CoTan(FOV / 2);
      m[2, 2] := -2 / (ZFar - ZNear);
      m[3, 2] := -(ZFar + ZNear) / (ZFar - ZNear);
      m[2, 3] := -1;
      m[3, 3] := 1;
      glLoadMatrixf(@m);

  6. #6

    Orthagonal X with perspective Y in OpenGL?

    Quote Originally Posted by Dan
    Very interesting question with the projection...
    I'm not sure how well it will work since I never needed such a wierd projection matrix
    Hmm. Out of curiousity you wouldn't know of a projection matrix that would let me scale all 360 degrees around you into a 60 degree projection screen width? I've been doing the math for that hard-coded.

    This is where I'm at:
    Code:
    function jangle(x,z:accuracy):longint;
    var
      ta:longint;
      ax,az:accuracy;
    begin
      if z=0 then begin
        if (x>0) then jangle:=JA90 else jangle:=JA270;
      end else if x=0 then begin
        if (z>0) then jangle:=0 else jangle:=JA180;
      end else begin
        ax:=abs(x);
        az:=abs(z);
        if ax>az then begin
          ta:=JA90-janglook^[trunc((az/ax)*Jadjust)];
        end else begin
          ta:=janglook^[trunc((ax/az)*JAdjust)];
        end;
        if &#40;x<0&#41; then begin
          if &#40;z<0&#41; then begin
            ta&#58;=ta+JA180;
          end else begin
            ta&#58;=JA360-ta;
          end;
        end else if &#40;z<0&#41; then begin
          ta&#58;=JA180-ta;
        end; &#123;else it's fine, leave it alone&#125;
        jangle&#58;=ta;
      end;
    end;
    the JangLook array is 0..jadjust, where jadjust is set to screen width * 6 (since I use the same function for both the 60 degree normal FoV, as well as the compressed 360 degree view). All those if statements mean I only need to calc the array to 45 degrees meaning I also don't have to worry too much about high angle skew errors.

    I'm actually considering using this routine TWICE, once to calculate screen X off of x and z, then calculate the distance to x and z, use that distance and Y to calculate the screen y.

    Basically:
    screen_x:=jangle(x,z);
    dis_x:=sqrt(x*x+z*z);
    screen_y:=jangle(disx,y);
    distance:=sqrt(dis_x*dis_x+y*y);

    That means hard coding all my calculations and doing everything as a flat projection though. (which means edge detection, dual calculation for elements going off the screen sides, etc, etc)
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  7. #7

    Orthagonal X with perspective Y in OpenGL?

    Up to 180 yes, but 360... I can't think of a way to do it with one matrix

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •