Developing an animation, currently at this stage:
http://jsfiddle.net/CoderX99/66b3j9wa/1/
Please avoid delving into the code, it's written in CoffeeScript and may not be beneficial for your mental well-being.
Imagine a "nordic" landscape with ships sailing by and cars moving along. The yellow sphere in the top left symbolizes a car, while the winding roads are represented by curves.
The yellow sphere is supposed to follow these CatmullRomCurve3
s precisely.
Let's work with a closed curve structure, which looks like this:
curveRoadNo2 = new THREE.CatmullRomCurve3([
new THREE.Vector3( 15, roadHeight, 11 ),
new THREE.Vector3( 12, roadHeight, 12 ),
...
] )
The figures are randomly inputted.
Next:
curveRoadNo2.closed = true
geometry = new THREE.Geometry()
geometry.vertices = curveRoadNo2.getPoints( 200 )
material = new THREE.LineBasicMaterial( { color : 0xa9c41e } )
curveObject = new THREE.Line( geometry, material )
scene.add( curveObject )
I would like to animate using getPoint(t)
and getTangent(t)
, but I am unsure how to proceed.
t = 0
animate = ->
requestAnimationFrame animate
t += 0.1
vehicle.position = curveRoadNo2.getPoint(t)
# More animation steps can be added here...
renderer.render scene, camera
animate()
Currently, the vehicle remains stationary. While I searched for solutions, they seemed overly complex and lengthy.
Suggestions or ideas in JavaScript are also appreciated.