Tricky math questions!
BlitzMax Forums/BlitzMax Beginners Area/Tricky math questions!
How do i show a 3d point on a 2d screen without using any 3d library, with distance too?
Also how do I calculate a objects 3d coordinates if I move it by so much for example (move from 0,0,0 at angle x,y,z would return the new position of the object)?
Thanks in advance :)
You need to "project" the point onto the plane.
http://en.wikipedia.org/wiki/3D_projection
Thanks will have a look, always been interested on simulating 3d without using one of the preset rendering systems :)
It's not so hard. Just divide the x and y coordinates with the z coordinate oft the 3D point to get the 2D x',y' coordinates:
x'=x/z
y'=y/z
Thanks René, would you perchance know the way to rotate the camera with the 3d point?
I don't really understand what you're after. Moving the 3D point in space?
Then next step would be using transformation matrices where it's getting a bit more complicated.
yeah moving the 3d point in space, ATM the code I have shows a 3d point on the screen now I would like to move around that 3d point if thats possible :).
As you have already guessed math is not my strong point, im more of an AI and logic person :)
Hm, I don't know if there is a smart way to fake 3D movement with a point. You can try to move the coordinates of the 3D point by user input. I.e.
Key Up - decreases z
Key Down - increases z
MouseMoveX - de/increases x
MouseMoveY - de/increases y
Then I would try to fake depth by making the point bigger the nearer you are to the point which means the nearer the z value is to zero the bigger the point. If z is negative the point is behind the camera (this is fake because a point is always the same size nevertheless how far away you are from that point).
If you want to make it correct (like a real 3D engine does), you will have to use vector and matrices math.
I see thanks will have a look at what I can come up with. I dont understand math much so vector and matrix math are beyond me :\
Here is a very poor 3d fake. Just to get an idea.
Use mouse and WASD.
SuperStrict
Graphics 1024, 768, 32
HideMouse
Type point
Global pointList:TList
Global mx%
Global my%
Global mxs%
Global mys%
Field x#
Field y#
Field z#
Field maxsize# = 100
Method New()
If pointList = Null Then pointList = CreateList()
ListAddLast pointList, Self
End Method
Function Create:point(_x#,_y#,_z#)
Local p:point = New point
p.x = _x
p.y = _y
p.z = _z
Return p
End Function
Function CreateRandom(_max#=1000)
Local x# = Rnd(-_max,_max)
Local y# = Rnd(-_max,_max)
Local z# = Rnd(-_max,_max)
point.Create(x,y,z)
End Function
Method Draw()
If Self.z < 0 Then Return
Local size# = Self.maxsize
If Self.z >= 1
size = Self.maxsize / (Self.z / 10.0)
End If
If size > Self.maxsize Then Return
SetColor 255,255,255
DrawOval Self.x -size/2, Self.y -size/2, size, size
End Method
Method Update()
If KeyDown(KEY_W) Then Self.z:- 1
If KeyDown(KEY_S) Then Self.z:+ 1
If KeyDown(KEY_A) Then Self.x:+ 1 / (Self.z/1000.0)
If KeyDown(KEY_D) Then Self.x:- 1 / (Self.z/1000.0)
Self.x:+ Float(mxs) / (Self.z/1000.0)
Self.y:+ Float(mys) / (Self.z/1000.0)
End Method
Function UpdateAll()
mxs = mx - MouseX()
mys = my - MouseY()
mx = MouseX()
my = MouseY()
If pointList = Null Then Return
For Local p:point = EachIn pointList
p.Update()
p.Draw()
Next
End Function
End Type
For Local i:Int = 0 To 1000
point.CreateRandom()
Next
While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
Cls
point.UpdateAll()
Flip
Wend
End
IT show simple example on where the x,y,z is
http://www.coolmath.com/coolthings/3dwireframe/index.htmlHope that help.
cheers
Thanks guys I will have a look, René thanks for the example I will have a tinker around and see what I can come up with :)