Hey

I'm working on an obj loader but the loaded objects are ... wrong lol The point is I don't know if the problem is in the obj file loader or in the triangle intersection part ... I checked a lot of stuff but nothing to do, I don't find the flaw !
Attached screen : The green stuff is supposed to be a dodecahedron ><
here is the obj loading part :
Function GetWord(stri as string, nb as integer) as string
dim as integer nbchr = len(stri), curspc=0
dim as string retstr=""
for i as integer = 1 to nbchr
if mid(stri,i,1) = " " or i=nbchr then
curspc += 1
if curspc = nb then return retstr
retstr = ""
else
retstr += mid(stri,i,1)
end if
next
return "ERROR"
End function
Sub SceneT.Load_OBJ(byval filen as string,byval Mat as MaterialT, P0 as vector = type(0,0,0), scale as vector = type(1,1,1) )
dim as integer ff = freefile, nbV=0,nbtriangles
dim as string linestr
dim as vector vertexlist(MAX_VERTICE)
Open filen for input as #ff
do
Line input #ff, linestr
select case left(linestr,1)
case "v"
'' add vertex
nbV += 1
vertexlist(nbV).x = val(GetWord(linestr,2))*scale.x + P0.x
vertexlist(nbV).y = val(GetWord(linestr,3))*scale.y + P0.y
vertexlist(nbV).z = val(GetWord(linestr,4))*scale.z + P0.z
case "f"
'' add triangles
this.Add_Triangle(vertexlist(val(GetWord(linestr,2))),vertexlist(val(GetWord(linestr,3))),vertexlist(val(GetWord(linestr,4))),Mat)
end select
Loop until eof(ff)
Close #ff
end suband the triangle intersection part :
dim as vector u, v, n, I
dim as Vector d, w0, w
dim as single r, a, b
u = This.p2 - this.p1
v = this.p3 - this.p1
n = u * v
if n.x=0 and n.y=0 and n.z=0 then return 0
d = CRay.d
w0 = CRay.O - this.p1
a = -dot(n,w0)
b = dot(n,d)
if (abs(b) < .00001) then return 0
r = a / b
if (r < 0) then return 0
I = CRay.O + r * d
dim as single uu, uv, vv, wu, wv, Det
uu = dot(u,u)
uv = dot(u,v)
vv = dot(v,v)
w = I - this.p1
wu = dot(w,u)
wv = dot(w,v)
Det = uv * uv - uu * vv
dim as single s, t, _D
_D = 1/Det
s = (uv * wv - vv * wu) * _D
if (s < 0.0 or s > 1.0) then return 0
t = (uv * wu - uu * wv) * _D
if (t < 0.0 or (s + t) > 1.0) then return 0
returnT = r
return 1Okay, there's some code here, and I know it's not easy to get what's going on in a someone else's code .. But if anyone already had this kind of problem, or have any idea, don't hestitate

nb : oh ! 'forgot to post the screenshot uhuh. thanks to clyde for pointing this out
