Vertex/image shading (in 2d, based on faked 3d..)

BlitzMax Forums/BlitzMax Programming/Vertex/image shading (in 2d, based on faked 3d..)

Unless I'm missing something, you're doing the cross product wrong. You want to take the cross product (topleft - topright) x (bottomright - topright)

And MultiplyVec in Yahfree's code isn't a cross product operation. In fact, I can't think what it could be for. Wikipedia has the proper definition for you, and here's a function you can add to your code:

Function CrossProduct:TVec3( vec1:TVec3, vec2:TVec3 )
	Return TVec3.Create( vec1.y*vec2.z - vec1.z*vec2.y, vec1.z*vec2.x - vec1.x*vec2.z, vec1.x*vec2.y - vec1.y*vec2.x )
End Function


So:
Local normal1:TVec3, normal2:TVec3, normal:TVec3
normal1 = _quad.topleft.copy()
normal2 = _quad.bottomright.copy()
normal1.SubtractVec(_quad.topright)
normal2.SubtractVec(_quad.topright)

normal = TVec3.CrossProduct( normal1, normal2 )


By the way, I think that in defining vector types, the operators should return new vector instances, not modify existing ones. Maybe it would be slow if you're doing loads of vector work, but in that case you should probably think about representing them with float triples.