|
-
Dec 3rd, 2002, 06:47 PM
#1
Thread Starter
Fanatic Member
3D field
I've been trying to make a small program that would move dots through simulated 3d space. Mainly for stuff like a starfield program or cool looking explosions and stuff...
VB Code:
Sub Movement (X,Y,Z,Speed,Angle1, Angle2)
'angle 1 is xy, angle2 is yz (supposedly)
X = X + Speed* Sin(Angle1) * Cos(Angle2) 'second one.. not sure
Y = Y + Speed * Cos(Angle1) * Cos(Angle2) '2nd again..
Z = Z + Speed * *Cos(Angle1) * Sin(Angle2) '???? no idea
End sub
Sub Placement (X,Y,Z)
'This assumes your viewpoint doesn't move
AngleXY = Angle from 0,0 to X,Y '(I have a proven function for
angles)
AngleXZ = 0,0 to X,Z
AngleYZ = 0,0 to Y,Z
'A^2 + B^2 = C^2
Diagonal = Sqr((X^2) + (Y^2)) 'get distance on x,y
Distance = Sqr((Diagonal^2) + (Z^2))
'Get total distance between view and point
TrueAngle = anglesub(0,0,Diagonal,Z)
'Angle from 0,0 to diagonal,z (duh)
TargetX = 320 + (((TrueAngle) / 90) * 320) * Sin(AngleXY)
TargetY = 240 + (((TrueAngle) / 90) * 320) * Cos(AngleXY)
'Use trueangle to decide where stuff will go
'blabla, set size of object here
Circle(TargetX, TargetY), Size, Color
Paint(TargetX, TargetY), Color
End Sub
Btw, it's in Qbasic, but it's so similar you probably can't tell except at the end
Don't pay attention to this signature, it's contradictory.
-
Dec 4th, 2002, 09:27 AM
#2
Addicted Member
-
Dec 4th, 2002, 09:28 AM
#3
Originally posted by Machaira
So what's the problem?
...good point...
-
Dec 4th, 2002, 03:17 PM
#4
Thread Starter
Fanatic Member
woops!
The problem is that things don't... move.. right.
No matter what I do the dot moves in a spiral motion, always going further away.. even if angle 2 is 90.. or 0.. anyways it should move in a straight line because I'm not changing the angles...
So it's probably the placement subroutine
Don't pay attention to this signature, it's contradictory.
-
Dec 6th, 2002, 01:36 AM
#5
Addicted Member
See if this makes sense:
eye_z = 1000
object_z = -1000
screen_z = 0
eye_to_screen = eye_z - screen_z
eye_to_object = eye_z - object_z
ratio = eye_to_object / eye_to_screen
using the law of similar triangles,
the x value of where line-of-sight
from eye to object meets the
screen:
projected_x = object_x / ratio
As object moves closer to eye, 'ratio' becomes smaller, and projected x gets very large.
if all you did was move the object z, you would see 'starfield movement'
-
Dec 6th, 2002, 07:43 AM
#6
Thread Starter
Fanatic Member
so..
So... trigonometry wasn't the right way... but what if I want the view to "turn", won't your system make it sortof difficult??
Don't pay attention to this signature, it's contradictory.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|