Skip to main content
gamedev.net
🔒 Locked

D3DXIntersect problems

Started by Harryu 1 reply 550+ views
Original Post
Harryu
Harryu
I use D3DXIntersect in my first-person game to let the character move up and down according to the terrain. It works very well usually, but if I try to scale my mesh (D3DXMatrixScaling) just before the terrain gets rendered, I can walk around a certain area in the level, but as soon as I pass a particular point, the camera just goes up in the air. I think that I start moving up in the air when I pass the boundaries of the un-scaled terrain. For example, if I start at 0,0 and my un-scaled terrain is from 0,0 to 20,20 , if I scale the terrain by 2, I think the character will start moving up into the air when it reaches 20,20 , rather than 40,40 where I would expect it. So my problem is getting D3DXIntersect to recognise the bit of the terrain that would not be there if it wasn't scaled.
sirob
sirob
I'm assuming you're modifying your world matrix in order to scale the terrain. If so, you need to modify the unprojection code to fit this new transformation. In your case, I assume you're manualy creating the ray using the player location, so you just need to scale the position (the ray start) by the same factor you scale your terrain. That is, if your ray should be at 40, 40, scale it down by two, so when you give it to D3DXIntersect, it is 20, 20, giving you the correct value.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
Harryu
Harryu
That worked!

Thanks a lot, that's been annoying me for a while now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.