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.

Author
Message
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 25th Sep 2006 19:59
Hi all.

I'm currently working on a 3d project, but I need to know how to transform the mouse coordinates to 3d coordinates of a plain surfus, in this case a matrix. And I don't have a clue how. Can anyone give me a tip on how to do it (I'm not asking you to code for me, just pointing out which direction I should take)?
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 25th Sep 2006 20:24
Things like mouse coordinates that do not have an actual third dimension can simply be put in as is...the x to the x, the y to the y. As long as the z is always the same, there is no trouble because they will all occupy the same plane.

You only have to use a projection scheme going the other way...from 3d to 2d, because in that case you are moving all of the z values into the same plane, which necessarily affects the other two quantities.
D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 26th Sep 2006 00:54
You also have to remember that the mouse coordinates are returned as pixels
and not 3D units. So, if you use the actual returned value which is an integer
from the mouse functions, you may want to multiply the value by a value less
than one. This will translate the pixel movement to a real number for 3D
positioning. The multiplier is up to you. It depends on the speed and accuracy
you are going for.

Oh, one more thing. Mr. X, did you look at my last reply about your array problem
in your last post? http://forum.thegamecreators.com/?m=forum_view&t=87639&b=7
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 26th Sep 2006 03:56 Edited at: 26th Sep 2006 04:00
this is from an rts tutorial my firend gave me a long time ago that should tell you exactly what you are looking for might take a while to figure out though


hope it helps

edit:just so you know it cant be copied to db right away and run to see if it works the only reason its in the code snippit brackets is so it wont make my post massive so you should copy it into microsoft word and sort out code from instruction first
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Sep 2006 05:16
surfus? You mean surface?

The code Jerok posted from my tutorial only works accurately if the surface is flat. So no hills on your matrix.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 26th Sep 2006 10:49
So all I have to do is to scale a matrix so that the coordinates will be simular, and then translate directly? The thing is that I want an object to get "attatched" to the mouse cursor so that I can place it.

Quote: "surfus? You mean surface?

The code Jerok posted from my tutorial only works accurately if the surface is flat. So no hills on your matrix."


Yes, I meant surface. The matrix won't have any hills of any kind. It is only a visual thing to help the one that's using the program. Anyway, I've allready looked at that code but didn't understand it.

Quote: "Oh, one more thing. Mr. X, did you look at my last reply about your array problem
in your last post?"


I did. The thing was that I needed to take a week off from the programming, and when I returned it had pased so long time... And I got this idea for this project. Well, I'll look into it again when I got the time. But not today, mayby tomorrow.
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 26th Sep 2006 17:19 Edited at: 26th Sep 2006 17:22
Quote: "The code Jerok posted from my tutorial only works accurately if the surface is flat. So no hills on your matrix.
"


the tut has two versions if you are using a matrix it has to be flat but theres more code at the bottom that shows how to make it work with a bumpy object

edit: try just using this code here


that should be easier for you
fungixl
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location:
Posted: 26th Sep 2006 23:59
lol...
this is what i did

of course u have to change how much "newover" is divided by depending on how far away from the camera u want to detect, due to perspective.it works for me though.
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 30th Sep 2006 13:13
Got it to work . I didn't use a terrain, I just put out an large, invisible object and used Jerok's second code on it. I have my reasons to use a matrix.
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 1st Oct 2006 18:32
Ok, now the object position it self at the cursor, but I got a new problem. I want to place objects with it, but it doesn't work correctly. No object is placed, at last none that I can see. Here is the function I use:
. I don't see whats the problem, so could anyone pleace help me.
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 2nd Oct 2006 02:03
the function code is fine but my guess is that its because you set the array number to 0 when defining the size (ex "objects( 0 ).sizeX") im assuming that this returns a value of zero making it so you cant see the object
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 2nd Oct 2006 09:06
Well, the "objects( 0 ).sizeX" part is the x-size of the object that I place with. I simply put it there because you should be able to size the object that you place. It's value should be 10, but I'll take a look at it.
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 3rd Oct 2006 03:02
Quote: "Well, the "objects( 0 ).sizeX" part is the x-size of the object that I place with. I simply put it there because you should be able to size the object that you place. It's value should be 10, but I'll take a look at it. "


my point was that you should change the 0 in objects( 0 ).sizeX to a 1 because i believe that any array with an array number of 0 will contain a value of 0 not entirely sure on this though
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 8th Oct 2006 16:08
I've tested to change the code, so that the placing object's size was called "objects( 1 ).sizeX" and so on, but it didn't work. The problem seems to be the variable itself. It seems that the code works, if I make so I always place on object with the size 10. But if I use variables, it doesn't work. This code works:
. The strange thing is that the code that I use to scale the object works, even if I use the variables:
. And when I use variables to rotate the objects it works. Can anyone help me?
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 13th Oct 2006 20:32
Does no one have any idea about what is wrong?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Oct 2006 06:57
Quote: " i believe that any array with an array number of 0 will contain a value of 0 not entirely sure on this though "


You can read and write to the 0th index just fine.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 16th Oct 2006 11:35
I tested to change it, even though I thought it propobly wouldn't do any difference, and it did no differnce at all.
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 22nd Oct 2006 13:22 Edited at: 22nd Oct 2006 13:22
Ok, I got it to work eventually by using globals instead of arrays and UDT's.

Login to post a reply

Server time is: 2024-09-25 11:25:20
Your offset time is: 2024-09-25 11:25:20