Horde3D http://horde3d.org/forums/ |
|
[solved]Problem with frustum culling ? http://horde3d.org/forums/viewtopic.php?f=1&t=2290 |
Page 1 of 1 |
Author: | DJLinux [ 21.09.2016, 15:42 ] |
Post subject: | [solved]Problem with frustum culling ? |
First sorry about my bad english. I animate via physics engine and render a bunch of cubes. If the the center of a cube geomtry (center of bounding box) are out of the window (camera frustum) the complete cube are not visible. What i'm doing wrong ? Thank you. Joshy Code: #include once "fbgfx.bi"
#include once "horde3d.bi" #include once "tokamak-c.bi" type AnimatedBody as neAnimatedBody ptr type RigidBody as neRigidBody ptr ' a static massless body with collision geometry function CreateAnimatedBodyBox(byval sim as neSimulator ptr, _ byval fWidth as single=1, _ byval fHeight as single=1, _ byval fDepth as single=1) as neAnimatedBody ptr var ab = SimulatorCreateAnimatedBody(sim) var geo = AnimatedBodyAddGeometry(ab) if fWidth <0.01 then fWidth =0.01 if fHeight<0.01 then fHeight=0.01 if fDepth <0.01 then fDepth =0.01 GeometrySetBoxSize(geo, fWidth,fHeight,fDepth) AnimatedBodyUpdateBoundingInfo(ab) return ab end function ' a dynamic body with mass and collision geometry function CreateRigidBodyBox(byval sim as neSimulator ptr, _ byval fWidth as single=1, _ byval fHeight as single=1, _ byval fDepth as single=1, _ byval fMass as single=1) as neRigidBody ptr var rb = SimulatorCreateRigidBody(sim) var geo = RigidBodyAddGeometry(rb) if fWidth <0.01 then fWidth =0.01 if fHeight<0.01 then fHeight=0.01 if fDepth <0.01 then fDepth =0.01 if fMass <1 then fMass =1 GeometrySetBoxSize(geo, fWidth,fHeight,fDepth) RigidBodySetInertiaTensor(rb,neBoxInertiaTensor(fWidth,fHeight,fDepth,fMass)) RigidBodySetMass(rb,fMass) RigidBodyUpdateBoundingInfo(rb) return rb end function function InitHorde3D(byval w as integer=640,byval h as integer=480) as boolean dim as integer bits screeninfo ,,bits ' create window with OpenGL context screenres w,h,bits,,fb.GFX_OPENGL if screenptr()=0 then screen 0 print "error: init OpenGL context !" beep : sleep : end 1 end if flip ' init Horde3D var ret = h3dInit() if ret=false then h3dutDumpMessages() return ret end function dim as integer iWidth=640,iHeight=480 'screeninfo iWidth,iHeight 'iWidth*=0.75 : iHeight*=0.75 if InitHorde3D(iWidth, iHeight)=false then screen 0 print "error: h3dInit() !" beep : sleep : end 1 end if var sim = CreateSimulator() if sim=NULL then h3dRelease() screen 0 print "error: CreateSimulator() !" beep : sleep : end 1 end if ' optinal set dump filename and title dim as string dumpFile = command(0) & ".html" dim as string dumpTitle = "tokamak 1.0.5 game physics test with: " & *h3dGetVersionString h3dutSetDumpFile (strptr(dumpFile)) h3dutSetDumpTitle(strptr(dumpTitle)) h3dutDumpMessages() ' Add resources var renderPipeline = h3dAddPipeline ("pipelines/forward.pipeline.xml") var skyBoxScene = h3dAddSceneGraph("models/skybox/skybox.scene.xml") var platformScene = h3dAddSceneGraph("models/platform/platform.scene.xml") var cubeScene = h3dAddSceneGraph("models/cube/cube.scene.xml") ' Load resources from content folder var contentDir = exepath() + "/Content" h3dutLoadResourcesFromDisk(strptr(contentDir)) ' optional dump log messages h3dutDumpMessages() ' usefull if loading of any resources are fails var skyboxNode = h3dAddNodes(H3DRootNode, skyboxScene) h3dSetNodeTransform(skyboxNode, 0,0,0, 0,0,0, 200,200,200) h3dSetNodeFlags (skyboxNode, H3DNodeFlags_NoCastShadow, true ) var platformNode = h3dAddNodes(H3DRootNode, platformScene) var platformBody = CreateAnimatedBodyBox(sim,150,2,150) AnimatedBodySetPosition(platformBody,0,-1,0) const MAX_CUBES = DEFAULT_RIGIDBODIES_COUNT const SQR_CUBES = sqr(MAX_CUBES) dim as TH3DNode cubeNode(MAX_CUBES-1) dim as RigidBody cubeBody(MAX_CUBES-1) for i as integer = 0 to MAX_CUBES-1 cubeNode(i) = h3dAddNodes(H3DRootNode, cubeScene) cubeBody(i) = CreateRigidBodyBox(sim) var col = i \ SQR_CUBES var row = i mod SQR_CUBES RigidBodySetPosition(cubeBody(i),-SQR_CUBES\2 + col*1.2 + (i and 1)*0.5,.5+row,0) next var cam = h3dAddCameraNode(H3DRootNode, "Camera", RenderPipeline) h3dSetNodeTransform(cam, 0,5,30, -10,0,0, 1,1,1) ' Setup position and size of the viewport h3dSetNodeParamI(cam, H3DCamera_ViewportXI , 0) h3dSetNodeParamI(cam, H3DCamera_ViewportYI , 0) h3dSetNodeParamI(cam, H3DCamera_ViewportWidthI , iWidth) h3dSetNodeParamI(cam, H3DCamera_ViewportHeightI, iHeight) ' Set camera parameters (field of view, asspect ratio, near plane, far plane) h3dSetupCameraView( cam, 60.0, iWidth / iHeight, 0.1, 1000.0 ) ' Setup size of the render target h3dResizePipelineBuffers(RenderPipeline, iWidth, iHeight) ' Add a light var light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP") h3dSetNodeTransform(light, 5,25,15, -90,0,0, 1,1,1) h3dSetNodeParamF(light, H3DLight_RadiusF , 0, 50) h3dSetNodeParamF(light, H3DLight_FovF , 0, 90) h3dSetNodeParamI(light, H3DLight_ShadowMapCountI, 1) h3dSetNodeParamF(light, H3DLight_ShadowMapBiasF ,0, 0.01) h3dSetNodeParamF(light, H3DLight_ColorF3, 0, 0.8) ' red h3dSetNodeParamF(light, H3DLight_ColorF3, 1, 0.4) ' green h3dSetNodeParamF(light, H3DLight_ColorF3, 2, 0.2) ' blue h3dutDumpMessages() ' shows the bounding boxes 'h3dSetOption(H3DOptions_DebugViewMode,1) ' usefull if something are wrong with trriangles 'h3dSetOption(H3DOptions_WireframeMode,1) dim as single xPos,yPos,zPos dim as single xRot,yRot,zRot dim as single matrix(15) dim as single ptr transform = @matrix(0) const CAM_TARGET = 10 while inkey()="" SimulatorAdvance(sim) RigidBodyGetOpenGLMatrix(cubeBody(CAM_TARGET),transform) h3dutLookAt(cam,0,5,30, transform[12], transform[13], transform[14], 0,1,0) for i as integer = 0 to MAX_CUBES-1 RigidBodyGetOpenGLMatrix(cubeBody(i),transform) h3dSetNodeTransMat (cubeNode(i),transform) next ' Render scene h3dRender( cam ) ' Finish rendering of frame h3dFinalizeFrame() ' swap buffers flip wend ' free all resources h3dRelease() DestroySimulator(sim) |
Author: | Irdis [ 21.09.2016, 21:01 ] |
Post subject: | Re: Problem with frustum culling ? |
I am not familiar with this programming language, but there are few things to point: 1) for i as integer = 0 to MAX_CUBES-1 cubeNode(i) = h3dAddNodes(H3DRootNode, cubeScene) cubeBody(i) = CreateRigidBodyBox(sim) var col = i \ SQR_CUBES var row = i mod SQR_CUBES RigidBodySetPosition(cubeBody(i),-SQR_CUBES\2 + col*1.2 + (i and 1)*0.5,.5+row,0) next Here you set the position of the physical body only and not the graphics part of the cube. So h3dSetNodeTrasform or ...TransMats should also be used in this for cycle. 2) Check your generated cube.scene.xml file. Do you have tx, ty, tz parameters for your mesh? If you have them and they are different from zero - that may be the cause (horde's aabb of the model and your physics aabb do no match in this case). These parameters should be set to zero, if they are present. 3) Horde recalculates AABB of the models and meshes only during h3dRender. That may also somehow affect your results. 4) Maybe there is a bug in Horde |
Author: | DJLinux [ 21.09.2016, 21:20 ] |
Post subject: | Re: Problem with frustum culling ? |
Hello Irdis thank you for your tips. Irdis wrote: Here you set the position of the physical body only and not the graphics part of the cube. So h3dSetNodeTrasform or ...TransMats should also be used in this for cycle. This is done in the render loop:Code: for i as integer = 0 to MAX_CUBES-1 RigidBodyGetOpenGLMatrix(cubeBody(i),transform) h3dSetNodeTransMat (cubeNode(i),transform) next ' Render scene h3dRender( cam ) Irdis wrote: 2) Check your generated cube.scene.xml file Code: <Model name="cube" geometry="models/cube/cube.geo"> <Mesh name="cube01" material="models/cube/cube.material.xml" batchStart="0" batchCount="36" vertRStart="0" vertREnd="24" /> </Model> Irdis wrote: 4) Maybe there is a bug in Horde No one notice the bug before I can't believe it.I won't go back to Irrlicht I'm in love with Horde3D now The clean C-interface is perfect for FreeBASIC. Joshy |
Author: | Irdis [ 22.09.2016, 08:39 ] |
Post subject: | Re: Problem with frustum culling ? |
Try setting transformation directly for meshes and not models. Unfortunately, horde's sample integration to bullet physics was lost, but I'll try to find the backup version, so you could see how it was done there. |
Author: | Volker [ 22.09.2016, 09:31 ] |
Post subject: | Re: Problem with frustum culling ? |
Unfortunately I don't have the original simple Bullet Physics integration sample available anymore myself, but there is still the physics integration within the game engine available: https://hcm-lab.de/public/Horde3D/trunk ... Component/ Of course this is not so easy to understand, as it is based on the components design of the game engine and such needs a bit more components to look at to see how all the transformations are applied. But at least I hope it is still working, although I haven't looked at it myself for several years now. |
Author: | Irdis [ 22.09.2016, 10:21 ] |
Post subject: | Re: Problem with frustum culling ? |
Here is the bullet integration sample, updated to Horde beta 4 version back in 2010. <deleted> (link lives for 30 days) |
Author: | DJLinux [ 23.09.2016, 10:35 ] |
Post subject: | Re: Problem with frustum culling ? |
Thank you Irdis and Volker for the tips and support. DJLinux wrote: <Mesh name="cube01" material="models/cube/cube.material.xml" batchStart="0" batchCount="36" vertRStart="0" vertREnd="24" /> I localized the problem it must be vertREnd="23" Looks like a typical pitfall if you begin with Horde 3D and create the first binary geo and xml files. Joshy |
Author: | Volker [ 23.09.2016, 22:40 ] |
Post subject: | Re: Problem with frustum culling ? |
Irdis wrote: Here is the bullet integration sample, updated to Horde beta 4 version back in 2010. Just wanted to download it myself for archiving, but my virus scanner complains about Trojan:Win32/Spursint.F!cl So if not intended to be uploaded, I guess you should scan your computer for malware. |
Author: | Irdis [ 24.09.2016, 09:05 ] |
Post subject: | Re: Problem with frustum culling ? |
Volker wrote: Irdis wrote: Here is the bullet integration sample, updated to Horde beta 4 version back in 2010. Just wanted to download it myself for archiving, but my virus scanner complains about Trojan:Win32/Spursint.F!cl So if not intended to be uploaded, I guess you should scan your computer for malware. That's odd, Avira didn't say anything... I'll scan with another antivirus (or virus total) and reupload on Monday. |
Author: | DJLinux [ 24.09.2016, 10:56 ] |
Post subject: | Re: [solved]Problem with frustum culling ? |
Why is the end of a batch a counter and the end of vertex the last vertex number ? batch is start,count and vertex is start,start+count-1 Would be better batch and vertex folow the same syntax / logic. batchStart = "" batchCount = "" verRStart = "" verRCount="" or batchStart = "" batchEnd = "" verRStart = "" verREnd="" Or does the current syntax makes more sense and I don't know it at the moment ? Joshy |
Author: | Irdis [ 27.09.2016, 15:39 ] |
Post subject: | Re: [solved]Problem with frustum culling ? |
Reuploaded Horde's integration to bullet: https://www.sendspace.com/file/5tyyvv VirusTotal - No viruses found Check. I've practically updated this sample to my latest changes in horde and will upload soon to github. DJLinux wrote: Why is the end of a batch a counter and the end of vertex the last vertex number ? batch is start,count and vertex is start,start+count-1 Would be better batch and vertex folow the same syntax / logic. batchStart = "" batchCount = "" verRStart = "" verRCount="" or batchStart = "" batchEnd = "" verRStart = "" verREnd="" Or does the current syntax makes more sense and I don't know it at the moment ? Joshy Well, batch count is another name to number of indices of a mesh. As for vertices - in renderer there is the following line: meshNode->getVertREnd() - meshNode->getVertRStart() + 1. So, basically, it was historically made and since then no one bothers |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |