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.

DarkBASIC Professional Discussion / Making a plain follow the mouse cursor

Author
Message
Kentaree
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 12th Jul 2003 03:44
Does anybody know how you can make a 3D object (in this case a plain) follow around the mouse cursor, while staying over the matrix?
My current code is:



The case with this code is that plain is textured with an arrow, which shows which direction the player is gonna walk when the right button is pressed. The plain's position is meant to be determined by the mouse's position, but I'm not very familiar with 2D to 3D calculations . Can anybody help me?

Cheers,
Kentaree.
Whatever I did I didn't do it!
UberTuba
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 12th Jul 2003 11:53
heres the code from my attempt at an rts. Ill put in the needed images later, when i can get a website that allows offsite linking.
its the mouse3d bit that u want

Life is a terminal disease.
You never survive it.
Stevo
23
Years of Service
User Offline
Joined: 4th Oct 2002
Location:
Posted: 13th Jul 2003 13:25 Edited at: 13th Jul 2003 13:30
Hi kennatree, I haven't done it yet, (I was doing it, but lostthe code for it). It is obviously quite difficult.

take the position of camera as 0.0,
edit: what I mean by this is, whereever the camera is, work from that position, and the bit below use sin & cos sin for distance ?

position object 2,(your plain),.. camera x camera z, you have to add a sin & cos to these, using the camera y angle

using center of screen add to that angle if the cursor is to the right, take away from that angle if the cursor is to the left.
that is the side ways position, for up & down find camera height, then
using triganomitry, use the camera height and then experiment to find an angle that will give you the hypoteuse from that you could work out the ground distance? you have to check though, does the camera height go to the bottom of the screen or the centre, what ever that is
you will have to add it to the camera height.
If you do get it done some way, let us know, thanks [b])

Puffy
23
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United States
Posted: 14th Jul 2003 09:15
Ugh... lemme see if I remember... its...
cx#=camerax#+(mousex()-(screenwidth/2)
cz#=cameraz#-(mousey()-(screenheight/2)
and then the cy# is easy
cy#=get ground height(cx#,cz#)
position object plain thingy cx#,cy#,cz# =\ that should work... outta my head... but the cx# and cz# are correct for the mouse math... I've used em loads of times... hehe... tell me if it works....o_O

EVERYONE LOVES THE PUFF!... =\
Puffy
23
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United States
Posted: 14th Jul 2003 09:16
O_O I think my code is slightly shorter than yours darkfluff...

EVERYONE LOVES THE PUFF!... =\
UberTuba
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 14th Jul 2003 17:25
only the mouse3d bit is the stuff u need the rests 4 manipulating the
matrix and stuff.

Life is a terminal disease.
You never survive it.
UberTuba
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 14th Jul 2003 17:32
yours only works if its positioned directly over the matrix at a certain height and even then it's not perfect. mine could be a hell of a lot better but yours is way off.
I dont think you remebered right :-s

Life is a terminal disease.
You never survive it.
Kentaree
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th Jul 2003 18:00
Lol, thanks guys. I'll have a look at all of these, although I agree with Darkfluff that Puffy's code only works directly above, at a certain height, and definitely not at such a weird angle as I'm using . Stevo's solution kinda confuses me though :-s.

Anyway, I'll have a look at which one works and I'll tell you.

Cheers,
Kentaree

Whatever I did I didn't do it!
Drum
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location:
Posted: 15th Jul 2003 12:12
look in code snippets for mouse co-ordinates on a matrix

go from there
Puffy
23
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United States
Posted: 15th Jul 2003 12:33
=\My codes just to translate the mouse from 2D to 3D... remember... the code after that is up to you...

EVERYONE LOVES THE PUFF!... =\

Login to post a reply

Server time is: 2026-07-21 12:50:31
Your offset time is: 2026-07-21 12:50:31