News:

Function Finder  Find all the functions within source code files

Main Menu

problem with getNormal

Started by monkeybot, July 01, 2011, 02:48:53 PM

Previous topic - Next topic

monkeybot


kevin


um.. good.. but  it'd be more useful to leave the question and answer.. so somebody who's having the same drama can see it.

monkeybot

#2
Quote from: monkeybot on July 01, 2011, 02:48:53 PM
no prob sussed it
right ok.

i was running the getnormal# example and couldn't see the blue line.

i thought the normal was at 90 degs from the surface(perpendicular)

monkeybot

Nope definitely cant work it out,

in the example the normal doesn't seem  to return anything.Whats going on??
i added this..
print ix#
print x2#
in the detection loop,when an intersect occurs  the values are the same i therefore deduce that the normal is always returning 0?

kevin


erml, now what was the question ? 

monkeybot

why does GetNormalX# return 0?

kevin


can i buy a vowel ??   

eg..
Quotei added this..
print ix#
print x2#

you added that to what ?????

monkeybot

in the detection loop, before the endif


; Calculate position of main circle
  HCentre = GetScreenWidth() / 2
  VCentre = GetScreenHeight() / 2
 
; Begin program main repeat/until loop
  Repeat
     Cls rgb(0,0,0)
   ; Draw a circle
     Circle HCentre, VCentre, 40, 0
     
     mx#=MouseX()
     my#=MouseY()
     
   ; Draw a line from 0,0 to Mouse position
     Line 20, 20, mx#,my#
     
   ; Check for Intersection
     If LineIntersectCircle(20 , 20, mx#, my#, HCentre, VCentre, 40,1)
       
        Print "Line Intersected Circle"
        ix#=GetIntersectX#(0)
        iy#=GetIntersectY#(0)
       
      ; draw a read circle to show the intersection point
        CircleC ix#,iy#,5,1,rgb(255,0,0)
       
      ; Project a ray in the intersection points normal
        x2#=ix#+(GetNormalX#(0)*50)
        y2#=iy#+(GetNormalY#(0)*50)
       
        LineC ix#,iy#,x2#,y2#,rgb(0,0,255)
       print ix#
       print x2#
       
     EndIf
     Sync
  Until esckey()
 






kevin

#8
 You're not getting the normal, because the intersection function in the example isn't told to return one.  It's only being told to return to the first point of intersection   is bit #0.  The normal for the first intersection point is bit #2

To return both we add bit 0 and bit 2 together.  


 If LineIntersectCircle(20 , 20, mx#, my#, HCentre, VCentre, 40,1+4)


The second intersection point (if one exists) is controlled by bits 1+3

So to return both points and normals


 If LineIntersectCircle(20 , 20, mx#, my#, HCentre, VCentre, 40,1+2+4+8)




To calc both points and no normals

 If LineIntersectCircle(20 , 20, mx#, my#, HCentre, VCentre, 40,1+2)



This is a pretty old change (Line Intersect Circle (Ray intersection) ), but unfortunately doesn't appear to be in the doc's
 




monkeybot

ahh it all makes sense now.cheers