UnderwareDesign
September 10, 2010, 05:04:48 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Meals Of The Dragon by Laskiapina (19,June,2010)
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: 3D Math Calc Problem  (Read 1602 times)
Kman1011
Full Member
***
Offline Offline

Posts: 101



« on: April 08, 2007, 07:20:08 PM »

Hey.

I've been working on a 3d engine concept to see if the trig functions would work to give me a 3D simulation. It seems to work fine until you look up and down with the arrow keys. For some reason the horizon seems to bend and get all distorted.

If you look side to side it all seems OK.

Here is the concept...

Imagine you are standing in an array of glass blocks 14 x 14 x 14 and the corner of each block is a dot.

Here is the code...

Code:
; PROJECT : 3DMathCalcs
; AUTHOR  : Kman
; CREATED : 4/3/2007
; EDITED  : 4/4/2007
; ---------------------------------------------------------------------

;3D Math Calcs
;Input Variables
HBearing=0
VBearing=0
lz=0
px=3
py=2
pz=6
fv#=90

;Math Calcs
Do
a$=Inkey$()
Cls 0
For lz=-60 To 60 Step 10
For ly=-60 To 60 Step 10
For lx=-60 To 60 Step 10
dx=lx-px
dy=ly-py
dz=lz-pz
pd#=Sqrt(dx^2+dy^2)
pdz#=Sqrt(dz^2+pd#^2)
Pang#=HBearing-ASin(dx/pd#)
Zang#=VBearing-ASin(dz/pdz#)
vx#=Sin(Pang#)*pd#
vy#=Cos(Pang#)*pd#
vz#=Sin(Zang#)*pdz#
;Print pdz#
;Print "Vx="+Str$(vx#)
;Print "Vy="+Str$(vy#)
;Print "Vz="+Str$(vz#)
Ppu#=GetScreenWidth()/((Sin(fv#/2)*vy#)*2)
Sx=(GetScreenWidth()/2)-Ppu#*vx#
If Pang#>=90 And Pang#<=270
Sy=(GetScreenHeight()/2)-PPu#*vz#
Else
Sy=(GetScreenHeight()/2)+PPu#*vz#
EndIf
If sx>0 And sx<800 And Sy>0 And Sy<600
  DotC Sx,Sy,RGB(255,255, 0)
EndIf
;Print vz#
;Print "Sx="+Str$(Sx)
;Print "Sy="+Str$(Sy)
Next lx
Next ly

Next lz
If RightKey()=True
Hbearing=Hbearing+5:If Hbearing>359 Then Hbearing=0
EndIf
If LeftKey()=True
HBearing=Hbearing-5:If Hbearing<0 Then Hbearing=359
EndIf
If UpKey()=True
Dec Vbearing:If Vbearing<-45 Then Vbearing=-45
EndIf
If DownKey()=True
Inc VBearing:If Vbearing>45 Then Vbearing=45
EndIf
If a$="8"
px=px+Sin(HBearing)
py=py+Cos(Hbearing)
EndIf
If DownKey()=True
Inc VBearing:If Vbearing>45 Then Vbearing=45
EndIf
SetCursor 0,0
Print Hbearing
Print VBearing

Print Sy



Sync
Loop
WaitKey


I think it has something to do with the conversion of virtual co-ordinates to screen co-ordinates


Any ideas Huh Huh


just to clarify-
    HBearing is angle looking across
    VBearing is looking up and down
    Px,y,z is your position
    fv#  is your field of vision is degrees

« Last Edit: April 08, 2007, 07:24:25 PM by Kman1011 » Logged

Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA
Kman1011
Full Member
***
Offline Offline

Posts: 101



« Reply #1 on: April 13, 2007, 08:59:38 PM »

Well I'll be!!! Cheesy

I have everyone STUMPED!!

This is a first.

Well no bother. I'll just take out the Z angle (Zang#) which looks up and down. Everything else works Ok.

I guess It's beyond everyone else... Wink I'll take it from here.
Logged

Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA
kevin
Development Team
Administrator
Hero Member
*****
Offline Offline

Posts: 9418



WWW
« Reply #2 on: April 13, 2007, 09:13:15 PM »


   You're aware that such functionality is built it right ?

   See. Projects/Examples/Rotation/RotateVertLIstToCamera.


Logged

Kman1011
Full Member
***
Offline Offline

Posts: 101



« Reply #3 on: April 13, 2007, 09:38:30 PM »

Quote
   You're aware that such functionality is built it right ?


No I wasn't.

 I have Version 1.62. If this fuction is under the 'Camera' heading in the docs. I don't have it. Huh

If you have a link to update my docs. I'd much appreciate it. (Outstanding example by the way.. Not sure how it works-- but i'll figure it out).

That's why I do these calcs from scratch. To better understand the 3D concept and carry in texture mapping, world collision, etc.

Thanx for getting back
 
Logged

Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!