TV3D advanced collision

BlitzMax Forums/BlitzMax Programming/TV3D advanced collision

Volker(Posted 2009) [#1]
What type of object is scene.advancedcollision
returning?
Shouldn't that work?
Local CollisionResult:CTVCollisionResult[]

CollisionResult = Scene.advancedcollision(pos1, pos2, cTV_OBJECT_MESH, cTV_TESTTYPE_ACCURATETESTING, hits) 

=Compile Error: Unable to convert from 'cTV_COLLISIONRESULT Array' to 'glimmer.tv3d65.CTVCollisionResult Array'


Gabriel(Posted 2009) [#2]
There are two completely different objects in TV3D. One is called CTVCollisionResult and one is called cTV_COLLISIONRESULT. One is a class, one is a struct. BlitzMax only has Types, of course, so they're easily confused. That function returns an array of cTV_COLLISIONRESULT structs not an array of cTVCollisionResult classes.


Volker(Posted 2009) [#3]
Hi Gabriel,

I want to convert a few lines of Visualbasic into Blitzmax
and I am getting confused. In VB scene.AdvancedCollision
seems to return an Int and 'collisionresult' is given as object to it?
Looks completely different to BM.

If scene.AdvancedCollision(pos1, pos2, collisionresult, TV_COLLIDE_MESH, TV_TESTTYPE_ACCURATETESTING, True) = True Then
               
vTstNrm.x = collisionresult.CollisionNormal.x
vTstNrm.y = collisionresult.CollisionNormal.y
vTstNrm.z = collisionresult.CollisionNormal.z
                               
vTstImp.x = collisionresult.CollisionImpact.x
vTstImp.y = collisionresult.CollisionImpact.y
vTstImp.z = collisionresult.CollisionImpact.z
               
slide = Vector(vTstImp.x + vTstNrm.x, vTstImp.y + vTstNrm.y, vTstImp.z + vTstNrm.z)           


This is one of mine experiments. It compiles but throws different errors
in runtime. Looks like I have no clue what I'm doing.
Function SlidingCollision:cTV_3DVECTOR(pos1:cTV_3DVECTOR, pos2:cTV_3DVECTOR)
	Local vTstNrm:cTV_3DVECTOR
	Local vTstImp:cTV_3DVECTOR
	Local hits:Int
	Local collisionresult:cTV_COLLISIONRESULT[] '??

	collisionresult = tvm.Scene.advancedcollision(pos1, pos2, cTV_OBJECT_MESH, cTV_TESTTYPE_ACCURATETESTING, hits) ' this line produces error in runtime
	
	If collisionresult <> Null
		Local cr:cTV_COLLISIONRESULT = CollisionResult[0]
		'
		If cr.bHasCollided = True		
			vTstNrm.x = cr.vCollisionNormal.x
			vTstNrm.y = cr.vCollisionNormal.y
			vTstNrm.z = cr.vCollisionNormal.z
			                               
			vTstImp.x = cr.vCollisionImpact.x
			vTstImp.y = cr.vCollisionImpact.y
			vTstImp.z = cr.vCollisionImpact.z
			Local slide:cTV_3DVECTOR = _cTV_3DVECTOR(vTstImp.x + vTstNrm.x, vTstImp.y + vTstNrm.y, vTstImp.z + vTstNrm.z)
   			Return slide
		End If
	End If
	Return Null
	      
End Function




Gabriel(Posted 2009) [#4]
You're right, I had to change the function prototype for this function. I wrote the wrapper three or four years ago, so I can't honestly remember why anymore. Either because of my naivety with C++ or because I was concerned it would let users crash the dll with incorrect parameters.

Your parameters look correct, but you're not supplying any value for hits. I think BlitzMax zeroes all the memory it allocates by default, so hits will be zero. The function will therefore be looking for zero collisions and make an array of size zero. You should set the hits parameter to the maximum number of hits you want reported. After the function has been called, it will contain the number of hits actually generated.


Volker(Posted 2009) [#5]
Thanks, I haven't seen that.


Volker(Posted 2009) [#6]
Ok, back again.
The intellisense shows me up: 'iNumOfHits: Int var'
That should give me the number of hits back in the var given to the function
instead of setting the number of hits or do I misinterpret this?

Doesn't matter, my new problem is:
Function SlidingCollision:cTV_3DVECTOR(pos1:cTV_3DVECTOR, pos2:cTV_3DVECTOR)
	
	Local hits:Int=2 ' settings this greater 1..
	Local collisionresult:cTV_COLLISIONRESULT[] 
	collisionresult = tvm.Scene.advancedcollision(pos1, pos2, cTV_OBJECT_MESH, cTV_TESTTYPE_ACCURATETESTING, hits)  ' ..gives an error in this line
end function

Setting hits bigger then 1 I get an
'Unhandled Exception:Attempt to index array element beyond array length'
in the moment of collision. Curious.


Gabriel(Posted 2009) [#7]
That should give me the number of hits back in the var given to the function instead of setting the number of hits or do I misinterpret this?

As I explained before, it's both. You set the maximum number of hits you want to test for and the value it holds afterwards is the number of actual hits generated. It's passed by reference so that I can create an int pointer in C++ and then TV3D can dereference the pointer to either read or write the value. In this instance, it does both.

Setting hits bigger then 1 I get an
'Unhandled Exception:Attempt to index array element beyond array length'
in the moment of collision.

Thanks, I've fixed that. I'll upload a fixed version later tonight when I'm back on my other computer. It looks like I was using the return value as the number of hits which I guess is not the case. That's one of the difficulties of wrapping an undocumented API.


kenshin(Posted 2009) [#8]
Gabriel: The Lite version linked here:
http://www.lunaticninja.com/tv3d/Module/Lite.zip
Does this have the advanced collision fix you mention? I only ask as I'm likely to be using this command at some stage.

Also, are you still going to be sending out up to date Pro versions when TV3D is updated, bugs are found in the wrapper, etc? I'm working on a project based partly on TV3D probably for the next few years at least, and I'm concerned that with the loss of glimmergames you may be stopping updates for the Pro version of the wrapper.


Volker(Posted 2009) [#9]
Yes, this version contains the advanced collision fix.
Tested yesterday.


kenshin(Posted 2009) [#10]
Thanks Volker.

Gabriel: Would you be kind enough to email me a copy of the latest Pro version with this fix please?


Gabriel(Posted 2009) [#11]

It would do if it was working. I've been trying to upload the fix since I posted a few days ago, but the site has been down. It was kind of Amon to offer to host it freely in the first place so I'm not going to pester him about it.

If anyone wants it, please just email me and I'll send it that way.

I'm just sending it to you now as I type this, Kenshin.

I assume you want it also Volker? I don't think I have a current email for you. Is the one in your profile ok to receive it?

Yes, I'll be updating the wrapper and fixing bugs. I'm just finishing off a game of my own in it so I'll obviously want to fix any bugs that crop up.


kenshin(Posted 2009) [#12]
If you want somewhere to put the Lite version that you can direct link to, then try electronicfiles.net. You get 1GB storage for free:) That's what I'm using for the tutorial set.

I was just a little worried was all, as I've always enjoyed getting the updates as TV3D development progressed. Now that I'm starting to get underway with a project, it's probably going to be important.

I can't wait to see what you've done for your game. I'm hoping it will stir up a lot more interest in the wrapper.

Thanks heaps.


Volker(Posted 2009) [#13]
Hi Gabriel,

I am still getting weird results using advancedcollision.
Setting iNumOfHits>1 works fine now, but If there is more then 1 object involved in collision, so it should return an array with length>1, I still get
'Unhandled Exception:Attempt to index array element beyond array length'
in the marked line.
picture
My mailadress in the profile is fine.