Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Updating Mouse Position?

Author
Message
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 27th Nov 2006 23:25
Hi all, hope you can help me out on this one, it's doing my head in !!!!!

I can't for the life of me figure out how to transfer the Z camera position when I release mousebutton 1.

What I'm trying to do is use the mouse for normal camera movement but when I press and hold the left mousebutton I want to be able to move along the camera Z axis using the Y axis of the mouse. It works, but when I release the mousebutton the Z camera position reverts back to its old position. I'm even now confusing myself trying to explain this problem!

So could anyone maybe suggest where I'm going wrong, and I think an explanation about camera and mouse movement would probably help me out too!

I have highlighted the relevant section of code with asterix.

p.s What the plural of asterix?


Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 28th Nov 2006 00:52 Edited at: 28th Nov 2006 00:53
Make a variable that holds the number 1 when the LMB is clicked. And if it equals 1 then make it hold that position.

p.s. Don't know.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Nov 2006 01:13 Edited at: 28th Nov 2006 01:15
Looking at your code, it looks like this is what you want:



TDK_Man

Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 28th Nov 2006 07:09
Hey thanks for the feedback!!!

TDK I have just looked over your code quickly and tried it. While MC=0 the scroll wheel on the mouse, no longer functions, updating camera Z position as in my original code.

Any ideas? (I think its the Z position anyway)

Thank you !!!!!
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Nov 2006 14:04 Edited at: 28th Nov 2006 14:20
Hi Ant,

This post has to do with your original code, but depending on your goal, you might want to go with TDK's method.

The problem you were describing seems to lie in this part of your code:

`Move camera with mouse
if mouseclick() <> 1
text x,y,"Camera X Position : "+str$(mousex())
text x,y+10,"Camera Y Position : "+str$(mousey())
text x,y+20,"Camera Z Position : "+str$(mousez())
position camera mousex(),mousey(),mousez()
endif

The last line before endif is the culprit. When the button is released, you are telling the camera to position itself at whatever the current mouse coordinates are. They do not corespond to the 3d world coordinates so you have the camera jump to where ever the (invisible) mouse pointer has moved.

I modified your original code and changed that line so that the position of the camera is determined relative to itself, but it repositions based on the mouse movement. It's almost just like you had with just a couple of variables added. I also added WRAPVALUE() to your object rotation routine to keep the angle from exceeding 360. I don't have a mouse wheel so I don't know how that is affected, but it works without one. Oh yeah, you'll have to change your position text so that it matches the camera pposition instead of the mouse position.



Enjoy your day.
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 28th Nov 2006 20:12
Hey thanks Latch, it works pretty good, but it ain't perfect
maybe the problem is how I'm trying to code it.

What I'm actually looking for is to be able to move around an object with one camera, the same as say a 3d modelling program like Wings 3d.

And although I never mentioned it before I might as well ask now, have another camera to follow the object in third person mode.

I don't really know alot about 3d or let's face it programming in general, so any advice and or explanations would be greatly appreciated!!!

Thanks.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Nov 2006 02:10
Hi Ant,

The camera movement in Wings can be replicated. It's not super complex, but it might be a little hard to conceptualize until you've actually done it. You seem to be on the right track though.

Here's a couple of hints:

You don't have to move the camera necessarily, you could fix the camera's position and rotate the object if you move the mouse left or right. In that case, you might do something like



Just to give you an idea.

If you want to actually move the camera around the object, think of it in terms of setting an orbit. This can be a little trickier. I use trig to do this kind of thing, but you could use the NEWXVALUE , NEWYVALUE, and NEWZVALUE to accomplish the same thing.

The idea is to get a focus (center of the circle) which would usually be the object you want to rotate around's position. Then you adjust the camera's x and z position relative to the object, then point the camera at the object.

With trig, it looks something like:

newcamerax=(distance to the object)*cos(camangley+angle increment)+objectposx
newcameraz=(distance to the object)*sin(camangley+angle increment)+objectposz


All I'm doing is changing polar coordinates to cartesian coordinates. Polar coordinates being based on a circle.

Like I mentioned before, you can use the NEWXVALUE and NEWZVALUE to do the same thing. Review of the DarkBASIC documentation should help out with those commands.

Enjoy your day.

Login to post a reply

Server time is: 2024-11-26 05:51:29
Your offset time is: 2024-11-26 05:51:29