  | | | clicking and Dragging models around a terrain | clicking and Dragging models around a terrain 2003-12-17 - By welchc@(protected)
Back
I've been trying to figure out how to click and drag models around a surface. I will eventually add a terrain follow script to the dragged object so it sticks to the surface. But, right now I'm having difficulty canniblising a script by Alex da Franca (constainDrag.dir). He is using X as the up axis. (It seems all the 'cool' coders use X up). So, I, not being as cool as the others, need Z to be my up axis. I can almost make it work but the model only moves along the y and not the x (or maybe its the other way around). I don't want the model to go up or down (Z) as I will have the terrain follow script deal with that.
I've pasted the script below. Could someone take a look at it and maybe point out where I am going wrong or point me in the right direction? Thanks!--Carl
property pSprite, pMember property pLeftTop property pCam property pModel property pOffset -- offset from clickloc to clicked models worldpos
on beginSprite me pSprite = sprite(me.spriteNum) pMember = pSprite.member pLeftTop = point(pSprite.left, pSprite.top) pCam = pSprite.camera pModel = void end beginSprite
on mouseDown me pModel = pCam.modelunderloc((the clickloc - pLeftTop)) if ilk(pModel) = #model then if pModel.name <> "terrain" then pOffset = (the clickloc - pLeftTop) - pCam.worldSpaceToSpriteSpace (pModel.worldposition) else pModel = void end if end if end
on mouseUp me pModel = void end
on mouseUpOutside me pModel = void end
on exitframe me if ilk(pModel) = #model then shift = the shiftdown camPos = pCam.worldposition
-- if shift then vHeight = pModel.worldposition.z -- vertical drag -- else vHeight = pModel.worldposition.x -- horizontal drag
vHeight = pModel.worldposition.x -- vHeight = pModel.worldposition.z p = pCam.spriteSpaceToWorldSpace((the mouseLoc - pLeftTop - pOffset))
put "p" && P v = p - camPos -- v = camPos - p v.normalize() put "v" && v if shift then -- vertical drag
-- if v[3] <> 0 then -- if the vector is parallel to the x-y plane we can't divide by 0 -- f = (p[3] - vHeight) / v[3] -- newWP = p - (v * f) -- newWP[2] = pModel.worldposition.y -- pModel.worldposition = newWP end if
else -- horizontal drag if v[1] <> 0 then -- if the vector is parallel to the x-z plane we can't divide by 0
f = (p[1] - vHeight) / v[1] pModel.worldposition = p - (v * f) end if end if end if end
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ Dir3d-l mailing list Dir3d-l@(protected) http://nuttybar.drama.uga.edu/mailman/listinfo/dir3d-l
|
|
 |