Jump to content


Photo

Converting Mouse Screen Coordinates Into 3d


  • Please log in to reply
96 replies to this topic

#1 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 22 March 2005 - 06:49 AM

The other day I wrote a script which takes the mouse coordinates (and among other things, the parameters for the 3D projection) and converts it into a 3D vector representing the direction the mouse is pointing in 3D space. With this vector, it is a trivial matter to detect if the mouse is pointing at an object or to project the mouse cursor onto a plane. I'm still tidying up the example of it, but I thought I'd go ahead and release the script now.

{
var mm,dX,dY,dZ,uX,uY,uZ,vX,vY,vZ,mX,mY,mZ, width, height, tFOV;
dX = argument3-argument0;
dY = argument4-argument1;
dZ = argument5-argument2;
mm = sqrt(dX*dX+dY*dY+dZ*dZ);
dX /= mm;
dY /= mm;
dZ /= mm;
uX = argument6;
uY = argument7;
uZ = argument8;
mm = uX*dX+uY*dY+uZ*dZ;
uX -= mm*dX;
uY -= mm*dY;
uZ -= mm*dZ
mm = sqrt(uX*uX+uY*uY+uZ*uZ);
uX /= mm;
uY /= mm;
uZ /= mm;
// v = u x d
vX = uY*dZ-dY*uZ;
vY = uZ*dX-dZ*uX;
vZ = uX*dY-dX*uY;
tFOV = tan(argument9*pi/360);
uX *= tFOV;
uY *= tFOV;
uZ *= tFOV;
vX *= tFOV*argument10;
vY *= tFOV*argument10;
vZ *= tFOV*argument10;
width = window_get_width();
height = window_get_height();
mX = dX+uX*(1-2*mouse_y/height)+vX*(2*mouse_x/width-1);
mY = dY+uY*(1-2*mouse_y/height)+vY*(2*mouse_x/width-1);
mZ = dZ+uZ*(1-2*mouse_y/height)+vZ*(2*mouse_x/width-1);
mm = sqrt(mX*mX+mY*mY+mZ*mZ);
global.mouse_dx = mX/mm;
global.mouse_dy = mY/mm;
global.mouse_dz = mZ/mm;
}

The arguments to the script are the same as d3d_set_projection_ext() (except for the last two). After the script executes, the components of the vector are stored in <global.mouse_dx, global.mouse_dy, global.mouse_dz>. This vector has its base at the camera's position. As I said earlier, I'm tidying up an example of its use and I'll upload that in the next few days. I may also write a tutorial on the use of vectors.
  • 10

#2 ThatGamesGuy

ThatGamesGuy

    Videogame designer

  • GMC Elder
  • 4766 posts
  • Version:GM8.1

Posted 22 March 2005 - 07:45 AM

When you're done making this, you could suggest this to be added to the '3D Faq & Guidelines' as a FAQ. Just a thought there. Good luck with it. :)
  • 1

#3 griffo game maker

griffo game maker

    GMC Member

  • New Member
  • 181 posts

Posted 22 March 2005 - 09:16 AM

I may also write a tutorial on the use of vectors.

I would like that. If anyone can do that it is you
  • 1

#4 darkmage

darkmage

    GMC Member

  • New Member
  • 518 posts

Posted 25 March 2005 - 12:31 PM

i hopy you have an example soon because when i use the script it gave me the wrong position back
  • 0

#5 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 25 March 2005 - 07:18 PM

It does not give you a mouse position back. It gives you a vector representing the direction the mouse is pointing. You can use this vector to see where on a plane the mouse would be or whether to mouse is pointing at some object. The problem is, writing a tutorial about this kind of thing is pretty much going to require me to teach at least a semester of high school math and go into more depth than what you'd see there.
  • 0

#6 darkmage

darkmage

    GMC Member

  • New Member
  • 518 posts

Posted 25 March 2005 - 08:53 PM

aah ok so global.mouse_dx and global.mouse_dy returns the x and y direction of the mouse
so i could get the the position back with
lenghtdir_x(point_distance(mouse_x,mouse_y,x,y),gl
obal.mouse_dx)
lenghtdir_y(point_distance(mouse_x,mouse_y,x,y),gl
obal.mouse_dy)

or am i wrong if so could you help me out
my projection code is
d3d_set_projection(x,y,200,x+cos(direction*pi/180),y-sin(direction*pi/180),196,0,0,1)
so if my last argument wasnt right please help me out thx and you will get credit for it

Edited by darkmage, 26 March 2005 - 09:15 PM.

  • 0

#7 Rune Hunter

Rune Hunter

    GMC Member

  • New Member
  • 317 posts

Posted 11 April 2005 - 01:13 AM

yes a tutorial would be nice, but just an example of using this (non commented) would be great!
  • 0

#8 biship

biship

    GMC Member

  • New Member
  • 29 posts

Posted 15 April 2005 - 08:02 PM

Ya, i agree, is there a tutorial for this, I wonder.... I'll look it up... :wacko:
  • 0

#9 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 15 April 2005 - 08:08 PM

Look for articles on vector math. This script basically gets the direction vector of the line that the mouse is on. If you learn how to represent planes and lines in 3D space, you shouldn't have any trouble figuring out how to use this script.
  • 0

#10 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 16 April 2005 - 12:57 AM

aah ok so global.mouse_dx and global.mouse_dy returns the x and y direction of the mouse
so i could get the the position back with
lenghtdir_x(point_distance(mouse_x,mouse_y,x,y),gl
obal.mouse_dx)
lenghtdir_y(point_distance(mouse_x,mouse_y,x,y),gl
obal.mouse_dy)


That doesn't sound right.

Look at it this way. You have the camera x,y and z. You have the global.mouse_dx,dy, and dz. The global.mouses are a vector (like an arrow) pointing outward from the camera x,y,z.

For example, you have a camera x,y,z of (5,8,25). You have global.mouses of <2,1,-8>. Add the mouses (the vector) to the camera coordinates and keep iterating (7,9,17), (9,10,9), (11,11,1) (13,12,-7) etc. All those points lie on the vector pointing from the camera. There are an infinte number of such points obviously.

Now you have to decide which of these many points you want. You will have to specify one of the three coordinates somehow. Let us say you want the x,y coordinates of the point where the vector intersects z=0.

That point lies in between (11,11,1) and (13,12,-7), so we have a bit of a problem. A moments thought should convince you that the point is 1/8 of the way in between. So we take 1/8 of the vector, that would be <2/8,1/8,-1>, and add it to the point (11,11,1). That gives us (11.25,11.125,0), which is the x y coordinate where the vector intersects z=0.

See my sig for an example.

Edited by mechanikos, 29 June 2005 - 12:43 AM.

  • 0

#11 Rune Hunter

Rune Hunter

    GMC Member

  • New Member
  • 317 posts

Posted 16 April 2005 - 02:46 AM

Yes, mechanikos, I said your script for 3d to 2d mouse cordinates didn't work in my game before. I found out why.

I had my z working differently so I had to replace your z with mine, now it works perfect! You both, Yourself, and you will get credit!

And I supose sence it is game maker I could sell my game using these codes? Though it probebly wouldn't sell just nice to know.

Edited by Rune Hunter, 16 April 2005 - 02:47 AM.

  • 0

#12 monkey dude

monkey dude

    Dazed and Confused

  • New Member
  • 424 posts

Posted 18 April 2005 - 06:14 PM

ok sorry to drag this up from the depths but i have a question. i do not understand vector maths at all. but looking at it i saw what might be happening, so i added on a bit of a hack to the end of your code as follows. (might not be exactly like this i am just remembering it)

.....
global.mouse_dx = mX/mm;
 global.mouse_dy = mY/mm;
 global.mouse_dz = mZ/mm;

var dist;
dist = obj_camera.z/global.mouse_dz
global.mouse_xx = global.mouse_dx*dist
global.mouse_yy = global.mouse_dy*dist
}

now if i take those new globals and make them relative to the cameras position, it almost works. but not quite. (might help to add here that the cameras direction is 90 degrees) it only works if i add the cameras z value to the _yy coordinate. then it works perfectly. but this is only for straight up. as i have said i dont know vector maths, i am very proud of myself to have even made a hack on to this that works.
so, question: what is the general way to make it give the right coordinates (at any angle).

thx

Edited by monkey dude, 18 April 2005 - 06:15 PM.

  • 0

#13 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 18 April 2005 - 07:44 PM

Well, I'd love to tell you what you're doing wrong, but I have honestly no idea what it is you're trying to do, as you haven't told us. :)
  • 0

#14 monkey dude

monkey dude

    Dazed and Confused

  • New Member
  • 424 posts

Posted 18 April 2005 - 08:21 PM

well ok. i just had a little play around and what i did worked just by coincidence i think.

i am (obviously?) trying to get the mouse position in the 3d world. i put your (yourselfs) code in to a script called xy_to_xyz. i added what i put in the previous post on to the end of it. the camera iz at z=200, and looks down on the world at a 45 degree angle, pointing up (90 degrees) so the projection looks like (x, y, z, x, y-z, 0, ...). after projecting the world (aspect ratio 640/480, angle 45 degrees), i execute the xy_to_xyz script with the same arguments minus the last 2.

the mouse then projects accurately on to the z=0 plane by using
obj_camera.x + global.mouse_xx
obj_camera.y + global.mouse_yy + 200 // or the cameras z value

that works. but, it doesnt work if you project differently (different angle or pitch as i have just found out)

so my question was, how do i manipulate the _dx,y,z variables to get me the 3d mouse coords no matter what my projection is like.

should have been more clear at the beggining.
  • 0

#15 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 18 April 2005 - 08:52 PM

You can't get the mouse's position in the 3D world. If that were possible, that's what this script would do. The mouse in 3D is a line, not a point.
  • 0

#16 monkey dude

monkey dude

    Dazed and Confused

  • New Member
  • 424 posts

Posted 18 April 2005 - 09:03 PM

are you saying that you dont know what i am trying to achieve?

edit: ill rephrase the last bit.

so my question was, how do i manipulate the _dx,y,z variables to get me the 3d mouse coords *when z = 0* no matter what my projection is like.

Edited by monkey dude, 18 April 2005 - 09:05 PM.

  • -1

#17 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 18 April 2005 - 09:04 PM

Yes, because what you're trying to do doesn't make any sense.
  • 1

#18 monkey dude

monkey dude

    Dazed and Confused

  • New Member
  • 424 posts

Posted 18 April 2005 - 09:08 PM

well umm.... does anyone understand what im trying to do? i dont really know how to explain it any better.
  • 0

#19 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 18 April 2005 - 09:38 PM

how do i manipulate the _dx,y,z variables to get me the 3d mouse coords *when z = 0*


That's exactly what my modification of Yourself's script does. Look in my sig.

Specifically, replace
mm = sqrt(mX*mX+mY*mY+mZ*mZ);
global.mouse_dx = mX/mm;
global.mouse_dy = mY/mm;
global.mouse_dz = mZ/mm;

placex=x-z*mX/mZ
placey=y-z*mY/mZ

The x, y and z are the camera x y and z. You don't really need to normalize the vector, what you need is the ratio between the x y and z components. In other words, how far along the x axis you move for each z decrement, and how far along the y axis you move for each z decrement. That's the mX/mZ and the mY/mZ part, the ratios. z/mZ is obviously how many z decrements you need to make. Multiply by mX and mY tells you how far along the axis to move.

Edited by mechanikos, 29 June 2005 - 12:44 AM.

  • 0

#20 monkey dude

monkey dude

    Dazed and Confused

  • New Member
  • 424 posts

Posted 18 April 2005 - 10:11 PM

woot thx. i kind of understand that.
  • 0

#21 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 19 April 2005 - 03:56 AM

Actually you know you had it (almost) right all along

global.mouse_dx = mX/mm;
global.mouse_dy = mY/mm;
global.mouse_dz = mZ/mm;

var dist;
dist = obj_camera.z/global.mouse_dz
global.mouse_xx = global.mouse_dx*dist
global.mouse_yy = global.mouse_dy*dist

so dist=obj_camera.z*mm/mZ and global.mouse_xx=obj_camera.z*mm*mX/(mm*mZ), which reduces to z*mX/mZ- the correct result. However when you set this value "relative to the camera" x and y as you said, you ADDED, where you should have SUBTRACTED. And you don't need to calculate the mm at all since it cancels out.

Edited by mechanikos, 19 April 2005 - 03:57 AM.

  • 0

#22 Aqwilla

Aqwilla

    GMC Member

  • New Member
  • 173 posts

Posted 22 June 2005 - 08:09 PM

Ok, i need to know all the needet arguments here. What should thay be...? Yourself said it's like d3d_set_projection_ext arguments, but i dont use gm6, I use 5.3a Xtreme3D, so i dont know the arguments...
  • 0

#23 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 23 June 2005 - 08:25 PM

This script is only intended for GM6's D3D functionality. If you use anything else, I can't help you. I can't even guarantee it'll work for anything else.
  • 0

#24 Aqwilla

Aqwilla

    GMC Member

  • New Member
  • 173 posts

Posted 24 June 2005 - 07:52 AM

Isn't it worth to try?
Couse i can't find any other option...

Now... Can i have the arguments.... please...
  • 0

#25 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 24 June 2005 - 01:17 PM

Just get the 6.x manual, you don't need to download GM 6.1 to find the arguments.
  • 0

#26 Tobs

Tobs

    GMC Member

  • New Member
  • 599 posts

Posted 09 September 2005 - 10:44 PM

So if i use this with your vector scripts, i can find a point on the line of the mouse when z==0? cus thats about what i need to do. Or is it just worth learning advanced math if i want to get involved in this kinda thing?

H3x
  • 0

#27 Eletron

Eletron

    789 Programmer

  • New Member
  • 282 posts

Posted 10 September 2005 - 08:25 PM

I NEED THE ARGUMENTS!!!!!! Yourself, there is a way to get the mouses coords in 3D, and I really need it! I have almost got it, but I SERIOUSLY need to know what the arguments for the script are. Thx! :o :P :o :) :angry: :(
  • -2

#28 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 10 September 2005 - 11:05 PM

Okay, if you had bothered to read what my first post said, you'd know what the arguments are. I state explicitly how to find the arguments.
  • 0

#29 Tobs

Tobs

    GMC Member

  • New Member
  • 599 posts

Posted 17 September 2005 - 07:42 AM

Any chance of uploading an example? I can almost get it to work, but i screwed it on the vecters, so it will go at an odd angle...

H3x
  • 0

#30 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 17 September 2005 - 08:12 PM

I have a working example of Yourself's scripts. Check my sig.
  • 0

#31 Tobs

Tobs

    GMC Member

  • New Member
  • 599 posts

Posted 20 September 2005 - 07:35 PM

Whoa, thats pritty cool.
Good thanks to both of you, this boosts in the ol' 3D math bit :(

H3x
  • 0

#32 Schalken

Schalken

    From Hyperspace

  • New Member
  • 109 posts

Posted 25 September 2005 - 05:41 AM

Un-freaking-beleivable. Yourself, I was seconds from PMing you asking how to convert mouse coordinates to a directional vector, before I found this thread (on Google!).

Thanks! :D :P :P

Edit: It works!

The way I had already tried to do it always resulted in a vector about 20% closer to the center of the screen for some reason. I think there was something wrong with the way I was converting pixels into degrees. Yours works like a charm, thanks again.

Edit: It turns out I need to convert pixels into angles somewhere else though. My equation was this: angle=(pixels/room_width)*view_span, where viewspan is the total horizontal viewspan in degrees. Am I totally wrong in the way that 3d world coordinates are converted to screen coordiantes?

Edited by Schalken, 25 September 2005 - 07:45 AM.

  • 0

#33 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 25 September 2005 - 02:03 PM

It turns out I need to convert pixels into angles somewhere else though. My equation was this: angle=(pixels/room_width)*view_span, where viewspan is the total horizontal viewspan in degrees


I'm guessing you are using the default projection, which for some reason has an aspect ratio of 1:1 rather than 1.3333:1. You need the aspect ratio to match the actual aspect ratio of your monitor.

EDIT: Not true about a 1:1 projection, the flaw in the default projection is it uses a FOV of 41 rather than 45 as the manual says. You do need the aspect ration to match the aspect ratio of the monitor.

Edited by mechanikos, 21 June 2007 - 10:43 PM.

  • 0

#34 Schalken

Schalken

    From Hyperspace

  • New Member
  • 109 posts

Posted 25 September 2005 - 02:28 PM

No, it's not the ascpect ratio. However, looking at Yourself's code, I think I found what the problem is, and is best portrayed via my little illustration...

Posted Image

My method assumes the projection type shown at right, however, looking at Yourself's code it appears the the projection on the left is the correct one. This means the equation should include the arctan of the mouse's coordinates as a factor of the image width and in relation to the center of the screen.

I'm about to try it out... unless, before I do, someone can tell me whether the projection on the left is the correct one or not.
  • 0

#35 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 25 September 2005 - 02:38 PM

The left one is correct. The projection is a trapezoidal pyramid. Otherwise when looking straight down on a level surface, a grid would be distorted, which is obviously not the case.

Edited by mechanikos, 25 September 2005 - 02:39 PM.

  • 0

#36 Schalken

Schalken

    From Hyperspace

  • New Member
  • 109 posts

Posted 25 September 2005 - 03:13 PM

Good point! I didnt think of that. Cheers.

Edit: Okay I'm wrong again, it's off by about 40%. :o

Yourself, can you show me how it works...

(Note: I have a matrix containing unit vectors describing the camera's three axis already)

Edited by Schalken, 25 September 2005 - 04:40 PM.

  • 0

#37 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 25 September 2005 - 06:42 PM

It's just vector addition. I add three vectors. One vector is a unit vector in the direction the camera is facing and the other two are just the up and right vectors scaled according to where the mouse is on the screen. Then I just add those three vectors and normalize the result.
  • 0

#38 Schalken

Schalken

    From Hyperspace

  • New Member
  • 109 posts

Posted 26 September 2005 - 03:30 AM

That's exactly what I did. Only it was easier becuase the camera matrix has those three vectors there already for me. It's obviously something wrong with the way I'm turning the mouse coordinate into a factor of the camera's right and up vectors.

Edit: I think I found what the problem was, I thought the camera angle is half of the total viewing angle, but they are the same thing.

Edit: Yeah it works perfectly now.

Edited by Schalken, 26 September 2005 - 05:33 AM.

  • 0

#39 gamemaker_master

gamemaker_master

    GMC Member

  • New Member
  • 174 posts

Posted 26 September 2005 - 09:22 AM

Ah well I don't understand any of that.
  • 0

#40 Smukho

Smukho

    GMC Member

  • New Member
  • 40 posts

Posted 31 December 2005 - 05:30 AM

Sorry but i can't understand how that works and what values to put into argument1, argument2, etc.

I want to make a 3D RTS game. But I can't click the buildngs. Is there a way to do this with your script?

Can you make an example (if you want without any explanations)?
  • 0

#41 GoaLitiuM

GoaLitiuM

    Previously Gamaster

  • New Member
  • 47 posts

Posted 31 December 2005 - 04:18 PM

the arguments are not the same as d3d_projection_ext when using third person...
i used arguments xfrom, yfrom, zfrom, xto, yto, zto...
but i tested to change *to -> *from and worked well :skull:
  • 0

#42 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 31 December 2005 - 04:20 PM

It doesn't use the znear or zfar arguments from that function, though, as they are not needed.
  • 0

#43 Smukho

Smukho

    GMC Member

  • New Member
  • 40 posts

Posted 15 January 2006 - 09:28 AM

I used Mechanikos examples and they look really good!!

Problem is I'm using Irrlicht and the Y and Z axis are interchanged. I changes all the Ys to Zs and vice versa (manually without using Find & Replace) but it still doesn't work. I checked everything else so it should work. But it doesn't.

Irrlicht has its own 3D coord to screen coord converter but not the other way around.

Can anyone rewrite the last bit of the scripts (atleast the Mouse click event) from Mechanikos waypointing example so it works in GMI? Hope this isn't asking too much :mellow:

EDIT:
Sorry if I bothered you but I fixed it myself! (almost anyway, just need to get the FOV right)

Edited by Smukho, 15 January 2006 - 10:06 AM.

  • 0

#44 SupremeJosh

SupremeJosh

    Vegetable Killer

  • New Member
  • 200 posts

Posted 27 January 2006 - 10:42 AM

Well, this might be quite usefull when I get around to making a level editor for my new game. I can't really test it yet, but with a little effort I might even be able to test it with an editor I made for an old fps :huh:.

Allthough I currently have no use for this, I understand what it returns and I must say that anyone making a 3D RTS or RPG will need this at some stage, so If you dont get it, its probably a good idea if you ever want to select units!

Yourself, is there any chance of getting a script that gives the x,y location of an x,y,z point? I know it is pretty much the basis of a 3D engine in itself, but if it is just switching a few things around I think that would also be useful. This could be used for such things as putting names above peoples heads etc without using 3d text, and putting sqaure things around stuff like in deus ex.
  • 0

#45 Da-Huntha

Da-Huntha

    GMC Member

  • New Member
  • 113 posts

Posted 07 February 2006 - 11:23 PM

I found a little error in mechanikos example though.
When you click on the horizon it'l make a division by 0.
I know how to circumvent divisions by 0, it's just that it might bug the unaware ;p

Edited by Da-Huntha, 08 February 2006 - 12:46 PM.

  • 0

#46 SupremeJosh

SupremeJosh

    Vegetable Killer

  • New Member
  • 200 posts

Posted 09 February 2006 - 07:21 AM

Hmmmm... Well I have just started an editor for my game, and of course this needs to be used to help me click on the ground etc and place buildings.

It works fine and stuff, although the point I calculated allways seems to be off slightly. I am not sure why this is, but I managed to fix it by just changing the FOV argument to 40, instead of 45. Although the FOV should be 45, it seems to work fine now at any place with the camera on any angle etc. I think for some reason the point was allways about 10% off from where it should be, so I just took down the FOV and it works? I know this is not a real solution, but does anyone know why the point allways seemed to be about 10% off depending on its distance on the center of the screen (i.e. obviously when clicking in the center of the screen it worked fine, and clicking near the edge of the screen gave me a point about 40 pixels off (In the 2d rendered image thingee)

Any ideas why it would do this would be helpful, as I would rather fix it properly rather than faking the FOV. I have checked views/window size and everything in case it was anything to do with window scaling etc.
  • 0

#47 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 09 February 2006 - 11:52 PM

the point I calculated allways seems to be off slightly


I am guessing that your projection aspect ratio does not match the aspect ratio of the screen, typically 1.333 to 1. I can tell you that Yourself's script and my implementation of it work flawlessly.

Except for the divide by zero error, which I have put in a hackish error handling.

EDIT: Once again, the flaw in the default projection is not the aspect ration, but the FOV.

Edited by mechanikos, 21 June 2007 - 10:45 PM.

  • 0

#48 Neur0n

Neur0n

    GMC Member

  • New Member
  • 277 posts

Posted 31 July 2006 - 04:37 PM

I just can't understand this... let alone make it work... can anybody who made it work make a small and quick tutorial on what to do to implement this thing properly?
  • 0

#49 Smukho

Smukho

    GMC Member

  • New Member
  • 40 posts

Posted 01 August 2006 - 10:05 AM

This code has a lot of vector math in it. If you can't understnad it then you probably need to learn the maths first. 'm in year 10 , I can understnad most of it....

Mechanikos has made an example of this in use. Look at his examples on his signature..I used that to learn how it works. That's how I managed to make it work in GameMakerIrrlicht!
  • 0

#50 Neur0n

Neur0n

    GMC Member

  • New Member
  • 277 posts

Posted 01 August 2006 - 04:18 PM

well, i have his example, but he modified Yourself's script and i don't quite understand what to do...

and here's the code that i use in the step event of the cursor object

scr_3dmouse_point(x,y+512,512,obj_p1.x,obj_p1.y,0, 0,0,1,45,640/480,1,32000)
 
x = lengthdir_x(point_distance(mouse_x,mouse_y,x,y),global.mouse_dx)
y = lengthdir_y(point_distance(mouse_x,mouse_y,x,y),global.mouse_dy)

but it seems that both my x and y movement of the mouse add to the X position of the cursor object and it's off scale by alot!
if anyone can help me i will PM the .gm6 ..

Edited by Neur0n, 01 August 2006 - 04:21 PM.

  • 0