Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

reflect vector on surface - like a lazer!

reflect vector on surface - like a lazer!

CoreyMurray
Enthusiast Enthusiast
1,888 Views
20 Replies
Message 1 of 21

reflect vector on surface - like a lazer!

CoreyMurray
Enthusiast
Enthusiast

hello,

I'm just getting started with MAXscript.

I want to reflect a line about a surface normal to create a new line to simulate light bouncing. The line is defined by the location of a point helper named lineOrigin01. The end of the line is at the center of an editable mesh object named reflectSurface01. I want to create a new line that is 100m long at the reflected direction.

 

Below is the best I could come up with, with chatGPT helping (or not helping but helping me learn). Get the objects, get the normal vector, reflect function, draw the line. If anyone has ANY tips or ideas they would be gladly received!

 

-- Define the start point of the line as the location of sunORIGIN object
startPoint = sunORIGIN.pos

 

-- Define the surface object to reflect off of as reflectSURFACE
surfaceObj = $reflectSURFACE

 

-- Get the center point of the surface object
surfaceCenter = (surfaceObj.max + surfaceObj.min) * 0.5

 

-- Get the normal vector of the surface object
surfaceNormal = normalize((surfaceObj.normal * surfaceObj.transform) as vector3)

 

-- Calculate the end point of the line using the reflect() function
endPoint = reflect(startPoint - surfaceCenter, surfaceNormal) + surfaceCenter

 

-- Create the line object with a length of 100 units
lineObj = createLine start:endPoint end:(endPoint + surfaceNormal * 100.0)

0 Likes
Accepted solutions (3)
1,889 Views
20 Replies
Replies (20)
Message 21 of 21

CoreyMurray
Enthusiast
Enthusiast
That's great, thanks so much for your help with this!
0 Likes