Notifications
Clear all

[Closed] Render light ray and reflected light ray as spline

 em3

I am looking for a way to view the light ray and reflection ray as a spline. The goal is to animate the position of the sun over time and see the path of the reflected light rays.

I found this code that will get the vector of a reflected ray from http://forums.cgsociety.org/showthread.php?t=800148 but am unsure about how to draw the spline that would represent that reflected ray. For clarity, I know how to draw a spline with maxscript but not sure about where to place the points.


-- Get tangent vector halfway Line01
pathVec = tangentCurve3D $Line01 1 .5

-- Get vector from Line02
rayVec = normalize ((getKnotPoint $Line02 1 2) - (getKnotPoint $Line02 1 1))

-- Calculate reflection vector
reflectionVec = 2 * (dot -rayVec pathVec) * pathVec + rayVec

Thanks!

1 Reply
 em3

how funny, searching for something else and I find this. Turns out I had solved the issue but forgot I made a post about it. :surprised

To draw a spline you need the two points (xyz coords) OR the vector (direction) of the future spline which in this example is derived from subtracting the positions of each object. In this example we have the plane’s position value as a point3 (x,y,z) value and the sphere’s position which I have manually set. We can get the normalized vector (direction) that the spline is oriented as a byproduct of both of these points.

If you’re not confused enough I can keep going.


fn drawthespline pointA pointB =

	
						(
local ss = SplineShape pos:pointA
addNewSpline ss
addKnot ss 1 #corner #line PointA
addKnot ss 1 #corner #line PointB
updateShape ss
ss
						)
						

(
p = plane lengthsegs:1 widthsegs:1
s = sphere pos:[30,50,12] radius:2
p1 = p.pos
p2 = s.pos 
v1 = normalize p2-p1 --direction of spline
s1 = drawthespline p1 (p1+(v1)*100) --draws a spline along a vector multiplied by 10
s1.wirecolor = color 255 13 14
s2=drawthespline p1 p2 --draw the spline from plane position to the sphere position
s2.wirecolor = color 0 255 28
)