Total Pageviews

Monday, April 21, 2014

physics.reflectRay()

physics.reflectRay()
សំរាប់ហ្វាំងសិននេះប្រើក្នុងការ reflect a vector ជាការត្រឡប់ដោយ physics.rayCast()
The reflected vector ត្រឡប់ជាតំណាង the direction of the reflection ហើយមាន magnitude (length) of 1
Syntax:
local reflected_ray_direction_x, reflected_ray_direction_y = physics.reflectRay( from_x, from_y, hits[1] )
from_x (required)
from_y (required)
hits[1] (required) An entry in the "hits" array, as returned by physics.rayCast().
សូមមើលកូដះ
local hits = physics.rayCast( from_x, from_y, to_x, to_y, "closest" )
if hits then
    -- There's at least one hit.
    print( "Hit count: " .. tostring( #hits ) )
    -- Output all the results.
    for i,v in ipairs(hits)
    do
        print( "Hit: ", i, object_name, " Position: ", v.position.x, v.position.y, " Surface normal: ", v.normal.x, v.normal.y)
    end

    print( "The first object hit is: ", hits[1].object, " at position: ", hits[1].position.x, hits[1].position.y, " where the surface normal is: ", hits[1].normal.x, hits[1].normal.y )
    local reflected_ray_direction_x, reflected_ray_direction_y = physics.reflectRay( from_x, from_y, hits[1] )
    print( "Reflected direction: ", reflected_ray_direction_x, " ", reflected_ray_direction_y )
else
    -- There's no hit.
end


No comments:

Post a Comment