So I'm trying to learn some 3D programming and am trying to do some experiments to better understand how things work.
One thing I'm trying is (with threejs) drawing a line and rotating it randomly.
I've never been a matrix guy, I always did things in 2D the way it "made sense in my head"
# CoffeeScript get_angle:-> Math.atan2(@props.velocity[1],@props.velocity[0]) rotate:(amount)-> ang = @get_angle() mag = @get_speed() # props is a velocity vector, [0] is x and [1] is y @props.velocity[0] = Math.cos(ang+amount)*mag @props.velocity[1] = Math.sin(ang+amount)*mag The amount passed in is random... Generating a random "walk"
I was wondering now how I could do the same in 3d? Right now the application runs fine (and I see my line), but it's "flat." There is no depth (due to the Z component not being modified) This is what I was thinking of doing, would this be a smart way of doing this?
CoffeeScript
get_angle:-> Math.atan2(@props.velocity[1],@props.velocity[0]) get_angle2:-> # not sure about this, but I feel like I need to be finding the angle from the z now and something else. rotate:(amount)-> ang = @get_angle() ang2 = @get_angle2() mag = @get_speed() # props is a velocity vector, [0] is x and [1] is y @props.velocity[0] = Math.cos(ang+amount)*mag @props.velocity[1] = Math.sin(ang+amount)*mag @props.velocity[2] = # I have a feeling here I would do something with ang2 and amount? I know that technically I would probably want to pass in the rotation for two of the components, but I thought maybe I could just try having it rotate the same for all three components.