Yea. I'm only calling ?ProjectVector3@@YAXHHHHH@Z. That's it.
Can you confirm if this is a problem in C++? I'm using PureBasic, though it should be just as fast.
This is my DBP code. I mirrored the Project3Dto2D in PureBasic but replaced the globals with static variables. It returns the result vector as an integer.
global project3d2d_screenxy,project3d2d_projection,project3d2d_view,project3d2d_world
project3d2d_screenxy=find free vector()
void=make vector3(project3d2d_screenxy)
project3d2d_projection=find free vector()
void=make matrix4(project3d2d_projection)
projection matrix4 project3d2d_projection
project3d2d_view=find free vector()
void=make matrix4(project3d2d_view)
view matrix4 project3d2d_view
project3d2d_world=find free vector()
void=make matrix4(project3d2d_world)
world matrix4 project3d2d_world
null = make vector3(100)
null = make matrix4(300) : projection matrix4 300
null = make matrix4(400) : view matrix4 400
null = make matrix4(500) : world matrix4 500
backdrop on
start=timer()
for i=1 to 200000
project3dTo2d(project3d2d_screenxy,25,35,45)
x#=x vector3(project3d2d_screenxy)
y#=y vector3(project3d2d_screenxy)
next i
finish1#=timer()-start
a=Project3D2D(25,35,45)
start=timer()
for i=1 to 200000
a=Project3D2D(25,35,45)
x#=x vector3(a)
y#=y vector3(a)
next i
finish2#=timer()-start
do
text 10,10,str$(finish1#/1000)
text 10,25,str$(finish2#/1000)
loop
wait key
end
function project3dTo2d(result as integer,x as float, y as float, z as float)
set vector3 result,x,y,z
view matrix4 project3d2d_view
project vector3 result,result,project3d2d_projection,project3d2d_view,project3d2d_world
endfunction
This is my PB function. All of my DBP calls are macros. There are no additional functions being called at all so it should be fast.
ProcedureCDLL Project3D2D(x.f,y.f,z.f)
Static FirstRun,ScreenXY,Projection,View,World
If Not FirstRun
ScreenXY=DBPFind_Free_Vector()
DBPMake_Vector3(ScreenXY)
Projection=DBPFind_Free_Vector()
DBPMake_Matrix4(Projection)
DBPProjection_Matrix4(Projection)
View=DBPFind_Free_Vector()
DBPMake_Matrix4(View)
DBPView_Matrix4(View)
World=DBPFind_Free_Vector()
DBPMake_Matrix4(World)
DBPWorld_Matrix4(World)
FirstRun=1
Else
;DBPSet_Vector3(ScreenXY,X,Y,Z) ; Commented for debugging
;DBPView_Matrix4(View) ; Commented for debugging
EndIf
DBPProject_Vector3(ScreenXY,ScreenXY,Projection,View,World)
ProcedureReturn ScreenXY
EndProcedure
http://3dfolio.com