View Full Version : Orthagonal X with perspective Y in OpenGL?
deathshadow
15-10-2007, 08:41 AM
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.
cairnswm
15-10-2007, 10:58 AM
Cant you precalculate the ATan etc?
For I := 1 to 360 do
MyATanArray[I] := ATan(I);
Etc?
JSoftware
15-10-2007, 03:42 PM
The famous InvSqrt function:
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;
Original c source:
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! :D
User137
15-10-2007, 07:16 PM
Optimized :D (just last line off)
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;
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:
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);
deathshadow
16-10-2007, 03:04 PM
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:
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 (x<0) then begin
if (z<0) then begin
ta:=ta+JA180;
end else begin
ta:=JA360-ta;
end;
end else if (z<0) then begin
ta:=JA180-ta;
end; {else it's fine, leave it alone}
jangle:=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)
Up to 180 yes, but 360... I can't think of a way to do it with one matrix
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.