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.

3 Dimensional Chat / mouse coordinates on a 3d matrix

Author
Message
TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 26th Jun 2003 10:49
hey fellas

i got this code from Jamesblond on the code snippets forum. thanks mate!!

with this code you can click and a sphere will appear under the mouse on the flat matrix.

im gonna start making a game soon but i need to do all the planning and stuff first of course. i cant tell you what the game is yet coz its top secret lol but the code here is the exact code that ill be needing. its perfect in everyway except one. it only deals with a flat matrix. with my game i need it to deal with a matrix that has different heights. im still in school tho and theyve just been teaching me easy stuff in maths so far....nothing thatll help me with this of course, so its vvvvv difficult for me to tweak it myself. i tried changing

position object 1,x#,y#,z#

to

position object 1,x#,get ground height (1,x#,z#),z#

and i also randomized the matrix

but this still did not suit my requirements. after examining the code further i realised that the click deals only with y=0 and therefore with this code the sphere is on top of the matrix, but not under the mouse anymore, rather it is over the point on y=0 where the mouse is being clicked. im not saying its a bad code or anything infact its great but if someone could tweak jamesblonds code just a bit i would be forever in their debt.

sorry if this is any trouble but i would really really appreciate it if someone could give me a hand here

cheers,
Teepee
Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 26th Jun 2003 22:52
Try it.

TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 27th Jun 2003 03:40
hey thanks man thats awesome....pretty much what i was looking for i could definitely use it.....thanks again

TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 27th Jun 2003 04:21
ok ive kinda tweaked it a little bit but im not sure that ive done it right....what i want is so that if i click on a point on the matrix, it returns the x,y,z location of the point you clicked on. as i said im no expert on maths so i dont really know what im doing lol so what ive done is i kept all of the variables and stuff you declared at the beginning and made it a gosub and the i only used the function "mouse2dto3d" and it doesnt work!! when it declares all that stuff at the beginning theres an error and the program just shuts down....not a normal runtime error but one of those windows ones where it says this program has performed an illegal operation. i got rid of most of the unnecessary variables there and its happy now.anyways i dont really kno if i should be including some of the other functions in my code as well so you see i really have no idea what im doing lol plzplzplzplzplz plz help me!!!

Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 27th Jun 2003 06:54 Edited at: 27th Jun 2003 07:25
Another matrix selection code.

TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 27th Jun 2003 07:46
its good...but not exactly what i want.....ok in a nutshell what i want is a piece of code that does this

a)creates a randomized matrix
b)on mouseclick calls upon a function that finds the xyz position of the mouse when it is clicked and prints that to the screen

i know thats a lot to ask but if you could just get that far more i promise i will put up a worship shrine in my room dedicated to you!!

PLEASE??

Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 27th Jun 2003 08:16
TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 27th Jun 2003 09:01
ah is see now

obviously i didnt explain myself properly lol

on your code there it gets the xyz position of the camera when you click....i need the actual position of the cursor to be converted to a 3d position on the matrix....like in your first code i basically need the xyz position of the small sphere when you click on the matrix. just like this...


im really sorry for this taking so long but like i said i really really really really really need this code and i dont know enough maths to do it myself...sorry for the trouble.

also thank for your help so far dmitros

Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 27th Jun 2003 19:15
To get the XYZ position of the mouse, you need to know the desired distance from the camera to the mouse. You can't just turn a 2D coordinate to a 3D coordinate that easily. If you know the position of the matrix, and the mouse is always on the matrix, then you can do it. Otherwise, no.

Xander
Bolt of Bolt Software Productions
Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 27th Jun 2003 19:37 Edited at: 27th Jun 2003 19:39
>> on your code there it gets the xyz position of the camera when you click....

This code returns the actual position in world coordinates of intersection point of a matrix and a ray projected from the camera in a direction of the cursor.



Function MakeObjectFromMatrix() builds a mesh from a matrix.

Function GetMatrixCloneIntersection(Obj) finds the actual position in world coordinates point of intersection with a matrix mesh (Obj).

Functions GetIntersectionPointX(),GetIntersectionPointY(),GetIntersectionPointZ() returns the X, Y, Z coordinates of intersection point.

Function GetDistanceToObject() returns the distance to the point of intersection.

If you want find position point of intersection in matrix coordinates, you need subtract a matrix position from a position of intersection point.

MatrixIntersectPointX#= GetIntersectionPointX()-Matrix Position X(matrix)
MatrixIntersectPointY#= GetIntersectionPointY()-Matrix Position Y(matrix)
MatrixIntersectPointZ#= GetIntersectionPointZ()-Matrix Position Z(matrix)

If you want only convert 2D coordinates of the cursor to the 3D, here there is a function 2Dto3D(). This function is projecting a line from camera to the cursor position on some range (Range#).



PS: Sorry for my English
D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 27th Jun 2003 20:23
Why so difficult DMiTR0S?
Never heard from intersect object?

God is real, unless declared integer.
TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 28th Jun 2003 05:19
look fellas sorry sorry again i just dont know much about this stuff but thanks for all your help.

in your code DMiTROS, the second one with just the 2d to 3d thing, how to i retrieve the x,y,z from it?? it looks kinda good to me but in my code ive got a matrrix all randomized and stuff and i call upon that function on mouseclick()=1....its in pretty much the same format as that code snippet i had before.....only problem is i dont know how to get the xyz!?!?!? lol i must seem preety stupid to all you geniuses so please please help me again...

Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 28th Jun 2003 14:27
TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 29th Jun 2003 05:33
well here i am again....still stuck on this...im really really soo sorry for all this trouble ive caused you dmitros but like i said i reallly need this code. anyways heres something i just whipped up using your code



what i want this code to do is if you put your cursor somewhere it will convert that position to 3d coordinates on the matrix including matrix height and if you press up the sphere will start moving in a direct line towards that position on the matrix. however what it does at the moment is when you press up the sphere will move towards the camera. this is definitely not what it is supposed to do but im sure you would be able to fix up this little bit of code wont you dmitros??? lol please if you could just change this code snippet for me so that it works perfectly and to my satisfaction i wont bother you again....pleasepleaseplease help me once again!!!

Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 29th Jun 2003 12:11
¹1


¹2

TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 30th Jun 2003 04:18
lol back again sorry. ok firstly that code you have there whenever i press up the sphere just moves along the side of the matrix to the corner whereas what i want it to di is to move to a destination on the matrix where the mouse is clicked. secondly what id really really like you to do, and this would make my life a whole lot easier is to change the code snippet i posted before, but only change the function in it because then ill be able to use the function in my games because itll be a nice little compact function that i can move around the place and do whatever with it. you might need to add a few more things around the place, variables and such.whatever. but the bottom line is if you can dont change any of the sphere stuff or the camera stuff (atleast not too much) if you can help it because all i really need is the function that converts 2d cursor coordinates to 3d matrix coordinates. thanks again.

Drum
21
Years of Service
User Offline
Joined: 10th Apr 2003
Location:
Posted: 1st Jul 2003 03:38
hey DMITROS,

That code there is exactly what ive been needing for a 3d chat i've been making. THANKYOU very much, if the final of this program ever is
released i will be sure to give you visual credit.

Does anyone have any ideas on converting the 3d coords of a box (for example) to 2d. This a very important feature of my program as I have to display the speechbubble sprite at co-ords of the character.

thanx
NICK

TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 1st Jul 2003 04:40
hey dmitros dont worry about the code anymore you see drum is my partner and this code was for some projects we were going to work on with the 3d chat being one of them and since he got it working i no longer need you to get me the code for the millionth time lol anyways youve been a great help so thanks a lot

TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 1st Jul 2003 09:26
but still give us a hand with the speech bubble thingo if you can

Eddie Gordo
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location: Ohio - USA
Posted: 1st Jul 2003 17:15
i don't know why you want me to post here teepee but...

if your asking me how i made the controls so that if i click on certain parts of the screen it moves, i just checked where on the screen the mouse was if it was at the top the character moved forward if it was at the top left he moves forward left.

if this is about the speech bubble i can't help you i dont use it anymore my game is mostly voice chat now, not much else, but i got the origional from DB.net a long time ago.

In our hearts and minds we keep the powers of love, hope and the hidden powers of evil in which we can mold a hero or daemon of ourselves-Book of Enoch Chapter III
Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 1st Jul 2003 18:44
Try Object Screen X() and Object Screen Y()

TeePee
21
Years of Service
User Offline
Joined: 18th Apr 2003
Location: Australia
Posted: 2nd Jul 2003 04:16
hey Dmitros thats awesome stuff just what we needed so thanks a lot for all of your help. well be sure to give you credit for your assitance in this 3d chat we're creating when we finally finish it

Login to post a reply

Server time is: 2024-05-20 10:46:12
Your offset time is: 2024-05-20 10:46:12