Results 1 to 6 of 6

Thread: 3D field

  1. #1
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 02
    Location
    Canada
    Posts
    860

    Angry 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:
    1. Sub Movement (X,Y,Z,Speed,Angle1, Angle2)
    2. 'angle 1 is xy, angle2 is yz (supposedly)
    3. X = X + Speed* Sin(Angle1) * Cos(Angle2) 'second one.. not sure
    4. Y = Y + Speed * Cos(Angle1) * Cos(Angle2) '2nd again..
    5. Z = Z + Speed * *Cos(Angle1) * Sin(Angle2) '???? no idea
    6. End sub
    7.  
    8. Sub Placement (X,Y,Z)
    9. 'This assumes your viewpoint doesn't move
    10.  
    11. AngleXY = Angle from 0,0 to X,Y '(I have a proven function for
    12. angles)
    13. AngleXZ = 0,0 to X,Z
    14. AngleYZ = 0,0 to Y,Z
    15.  
    16. 'A^2 + B^2 = C^2
    17. Diagonal = Sqr((X^2) + (Y^2)) 'get distance on x,y
    18. Distance = Sqr((Diagonal^2) + (Z^2))
    19. 'Get total distance between view and point
    20. TrueAngle = anglesub(0,0,Diagonal,Z)
    21. 'Angle from 0,0 to diagonal,z (duh)
    22.  
    23. TargetX = 320 + (((TrueAngle) / 90) * 320) * Sin(AngleXY)
    24. TargetY = 240 + (((TrueAngle) / 90) * 320) * Cos(AngleXY)
    25. 'Use trueangle to decide where stuff will go
    26.  
    27. 'blabla, set size of object here
    28.  
    29. Circle(TargetX, TargetY), Size, Color
    30. Paint(TargetX, TargetY), Color
    31. 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.

  2. #2
    Addicted Member
    Join Date
    Aug 02
    Location
    Baltimore, MD
    Posts
    230
    So what's the problem?

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 02
    Location
    @ Opera Software
    Posts
    10,191
    Originally posted by Machaira
    So what's the problem?
    ...good point...

  4. #4
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 02
    Location
    Canada
    Posts
    860

    Unhappy 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.

  5. #5
    Addicted Member
    Join Date
    Aug 02
    Posts
    192
    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'

  6. #6
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 02
    Location
    Canada
    Posts
    860

    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
  •