<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[GMan's Mods & Stuff — Terrain collisions]]></title>
		<link>https://gprogs.com/viewtopic.php?id=186</link>
		<atom:link href="https://gprogs.com/extern.php?action=feed&amp;tid=186&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Terrain collisions.]]></description>
		<lastBuildDate>Sat, 14 Apr 2007 21:02:22 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=777#p777</link>
			<description><![CDATA[<p>thanks Conard!&nbsp; it would be neat to wrap this up into a new collisionresponseanimator specifically for terrain colliding.</p>]]></description>
			<author><![CDATA[null@example.com (gman)]]></author>
			<pubDate>Sat, 14 Apr 2007 21:02:22 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=777#p777</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=775#p775</link>
			<description><![CDATA[<p>It turns out that the Irrlicht collision system just isn&#039;t advanced enough to do this. If you want terrain collision detection, you will need to write your own functions. Here is the code I use:<br /></p><div class="codebox"><pre><code>Global gravity = 0.1
Global groundoffset:vector3df = _VECTOR3DF(0, 0, 0)

 Function getHeight:Float(dev1:IrrlichtDevice , ground:ITriangleSelector , pos:vector3df , maxHeight:Float)
    Local colMan:ISceneCollisionManager = dev1.getSceneManager().getSceneCollisionManager()
    Local yAxis:vector3df = (_VECTOR3DF(0 , maxHeight , 0))
    Local tmppos:vector3df = (_VECTOR3DF(pos.getX() , pos.getY() - yAxis.getY() , pos.getZ()))
    Local ray:line3df = Line3df.createFromVects(pos , tmppos)
    Local ptoCol:vector3df = (_VECTOR3DF(0, 0, 0))
    Local triangle:triangle3df = triangle3df.create()
    
    If(colMan.getCollisionPoint(ray , ground , ptoCol , triangle)    )
        Return ptoCol.getY()
    Else
        Return maxHeight
    EndIf
EndFunction


Function ApplyGravity(msecs)
 Local pos1:vector3df
 pos1 = myMesh.getPosition()
 pos1.setY(pos1.getY() + 100000)
 Local momentum

 Local THeight:Float = getHeight(myDevice, myFloor, pos1, 110000)
 Local XHeight:Float = getHeight(myDevice, myFloor, _VECTOR3DF(pos1.getX()-1, pos1.getY(), pos1.getZ()), 110000)
 Local ZHeight:Float = getHeight(myDevice, myFloor, _VECTOR3DF(pos1.getX(), pos1.getY(), pos1.getZ()-1), 110000)
 pos1.setY(pos1.getY() - 100000)
 momentum = momentum + gravity * msec / 1000.0

 If(pos1.getY() &lt; (THeight + groundOffset.getY()))
  pos1.setY(THeight + GroundOffset.getY())
  momentum = 0
  &#039; this should prevent climbing steep slopes
  If(THeight &lt; XHeight-1) pos1.setX(pos1.getX() + walkSpeed/10.0)
  If(THeight &gt; XHeight+1) pos1.setX(pos1.getX() - walkSpeed/10.0)
  If(THeight &lt; ZHeight-1) pos1.setZ(pos1.getZ() + walkSpeed/10.0)
  If(THeight &gt; ZHeight+1) pos1.setZ(pos1.getZ() - walkSpeed/10.0)
 EndIf

 myMesh.setPosition(pos1)
 myMesh.updateAbsolutePosition()
EndFunction</code></pre></div><p>ps. this is some code I found on the Irrlicht forums that I converted.</p>]]></description>
			<author><![CDATA[null@example.com (Conard)]]></author>
			<pubDate>Sat, 14 Apr 2007 18:51:06 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=775#p775</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=757#p757</link>
			<description><![CDATA[]]></description>
			<author><![CDATA[null@example.com (Conard)]]></author>
			<pubDate>Thu, 12 Apr 2007 14:18:50 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=757#p757</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=751#p751</link>
			<description><![CDATA[<p>ah thx Conard.&nbsp; i was looking for differences between v1.2 and v1.3.&nbsp; did you post the Q at the irrlicht forums?&nbsp; if not, i see someone else just reported the exact same issue.</p>]]></description>
			<author><![CDATA[null@example.com (gman)]]></author>
			<pubDate>Thu, 12 Apr 2007 12:28:20 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=751#p751</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=749#p749</link>
			<description><![CDATA[<p>Ok, but note that this is not something that came with the 1.3 update, it was there before. I might be able to fix it using a physics engine for collisions, but I don&#039;t really feel like implenting Newton just for collisions with terrain.</p>]]></description>
			<author><![CDATA[null@example.com (Conard)]]></author>
			<pubDate>Thu, 12 Apr 2007 10:53:28 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=749#p749</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=747#p747</link>
			<description><![CDATA[]]></description>
			<author><![CDATA[null@example.com (gman)]]></author>
			<pubDate>Thu, 12 Apr 2007 02:06:43 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=747#p747</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=746#p746</link>
			<description><![CDATA[<p>i have now replicated the problem on all 3 OS.&nbsp; i know its not a mod issue so im not sure how well im going to be able to help.&nbsp; i will try though.</p><p>on a side note, are you running PPC processor?&nbsp; did you have to ranlib the libIrrlichtMac.a?</p>]]></description>
			<author><![CDATA[null@example.com (gman)]]></author>
			<pubDate>Thu, 12 Apr 2007 00:58:37 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=746#p746</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=743#p743</link>
			<description><![CDATA[]]></description>
			<author><![CDATA[null@example.com (Conard)]]></author>
			<pubDate>Wed, 11 Apr 2007 22:08:11 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=743#p743</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=742#p742</link>
			<description><![CDATA[<p>i will check it out tonight when i try out the mac version.&nbsp; &nbsp;did you need the .nib file and if so, where did you place it?</p>]]></description>
			<author><![CDATA[null@example.com (gman)]]></author>
			<pubDate>Wed, 11 Apr 2007 21:58:25 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=742#p742</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=741#p741</link>
			<description><![CDATA[<p>I am using the mac version.<br />Normally I would use your SmoothEventReceiver, but at the time I wrote that code the addons waren&#039;t updated yet, using the SmoothEvenReceiver makes you walk smooth as supposed <img src="https://gprogs.com/img/smilies/smile.png" width="15" height="15" alt="smile" />. <br />Also, you will only get stuck on small slopes, so you really have to walk forward a fair bit &#039;till you notice it (yea I could have better edited the player position).</p>]]></description>
			<author><![CDATA[null@example.com (Conard)]]></author>
			<pubDate>Wed, 11 Apr 2007 21:40:31 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=741#p741</guid>
		</item>
		<item>
			<title><![CDATA[Re: Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=740#p740</link>
			<description><![CDATA[<p>greetings <img src="https://gprogs.com/img/smilies/smile.png" width="15" height="15" alt="smile" />&nbsp; my box is stuttering simply due to the key input, but i dont seem to get stuck at all with the above code.&nbsp; i know of the reports you have seen on the irrlicht forums though.&nbsp; are you using the windows or mac version?</p>]]></description>
			<author><![CDATA[null@example.com (gman)]]></author>
			<pubDate>Wed, 11 Apr 2007 21:32:53 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=740#p740</guid>
		</item>
		<item>
			<title><![CDATA[Terrain collisions]]></title>
			<link>https://gprogs.com/viewtopic.php?pid=733#p733</link>
			<description><![CDATA[<p>I&#039;m trying to have a model walk over a terrain, but I ran into a problem, the player seems to get stuck on very little slopes of the terrain.<br />In the Irrlicht forums there were some people with the same problem, but I still couldn&#039;t get it fixed.</p><p>Here is a simple example I threw together:<br /></p><div class="codebox"><pre><code>SuperStrict
Framework BRL.Blitz
Import BRL.StandardIO
Import Irrlicht.Core

&#039; player cube
Global player:ISceneNode

&#039; for handling user input
Type MyEventReceiver Extends IEventReceiver

    Field Terrain:ISceneNode

    Method setTerrain(terr:ISceneNode)
        Terrain=terr
    EndMethod

    Method OnEvent:Int(event:SEvent)

        &#039; check If user presses the key &#039;W&#039; or &#039;D&#039;
        If event.getEventType()=EET_KEY_INPUT_EVENT
        
            Local key:Int=event.getKeyInputKey()
            
            Select key
                &#039; move forward
                Case EKEY_KEY_W  
                    Local p:vector3df=player.getPosition()
                    Local v:vector3df=_VECTOR3DF(p.getX(),p.getY(),p.getZ()+20)
                    player.setPosition(v)
                    Return True    
                &#039; move backward    
                Case EKEY_KEY_S
                    Local p:vector3df=player.getPosition()
                    Local v:vector3df=_VECTOR3DF(p.getX(),p.getY()-0.2,p.getZ()-20)
                    player.setPosition(v)
                    Return True                
            EndSelect            
        EndIf
        
        Return False
    EndMethod

    Function generate:IEventReceiver()
        Return New MyEventReceiver
    EndFunction
EndType

Local device:IrrlichtDevice=IrrlichtDevice.create(EDT_OPENGL , _DIMENSION2DI(800,600))
If device.handle=0 Then Return 

Local driver:IVideoDriver=device.getVideoDriver()
Local smgr:ISceneManager=device.getSceneManager()
Local env:IGUIEnvironment=device.getGUIEnvironment()

Local camera:ICameraSceneNode=smgr.addCameraSceneNodeFPS(Null,100.0,1200.0)
camera.setPosition(_VECTOR3DF(1900*2,255*2,3700*2))

Local terrain:ITerrainSceneNode=smgr.addTerrainSceneNodeFromFile(&quot;terrain-heightmap.bmp&quot;)
terrain.SetScale(_VECTOR3DF(40, 4.4, 40))
terrain.setMaterialFlag(EMF_LIGHTING, False)
terrain.setMaterialTexture(0, driver.getTexture(&quot;terrain-texture.jpg&quot;))

Local selector:ITriangleSelector=smgr.createTerrainTriangleSelector(terrain, 0)
terrain.setTriangleSelector(selector)
selector.drop()

player=smgr.addCubeSceneNode()
player.setPosition(_VECTOR3DF(1900*2,255*2,3700*2))
player.setScale(_VECTOR3DF(4.0,8.0,4.0))

Local anim:ISceneNodeAnimator=smgr.createCollisionResponseAnimator( ..
    selector, player, _VECTOR3DF(18,36,18), _VECTOR3DF(0,-.1,0), _VECTOR3DF(0,10,0))
player.addAnimator(anim)

Local receiver:IEventReceiver=IEventReceiver.create(MyEventReceiver.generate)
device.setEventReceiver(receiver)

While (device.run())
    
    &#039;start drawing everything
    driver.beginScene(True,True,_SCOLOR(255,30,80,200))
    
    smgr.drawAll()
    env.drawAll()
    
    driver.endScene()
    
Wend

device.drop()</code></pre></div><p>It uses a heightmap &#039;terrain-heightmap.bmp&#039; and a texture &#039;terrain-texture.jpg&#039; wich are located in the Irrlicht media folder. (don&#039;t mind the lack of commands, I threw this together rather quickly <img src="https://gprogs.com/img/smilies/tongue.png" width="15" height="15" alt="tongue" />)</p><p>Does anyone know how I can fix this?</p><p>Thanks in advantage.</p>]]></description>
			<author><![CDATA[null@example.com (Conard)]]></author>
			<pubDate>Wed, 11 Apr 2007 16:04:35 +0000</pubDate>
			<guid>https://gprogs.com/viewtopic.php?pid=733#p733</guid>
		</item>
	</channel>
</rss>
