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 / How to click in 3d?

Author
Message
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 17th Jul 2003 08:53
Im sure its been asked before, but whats the easiest, simplest, newbiest way to tell what youre clicking on in 3d? Really all I want to do is tell what coord on a matrix youre clicking on.

I thought about just shooting out a little invisible checker point using newxyzvalue() (like a bullet), and waiting for it to collide with something. But im not sure how to accurately offset the angle/position if youre clicking anywhere besides the dead center of the screen. Is such a method even worth the effort? It seems like it would get the job done.

Thanks in advance for any help
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 17th Jul 2003 12:46
I have not had to use it yet but 'Intersect Object' is the function to use.

You need collision switched on for the objects you are clicking on, then you pass into this two coordinates, for a mouse one would be the mouses position in 3D space (IE at the camera +/- its screen pos) the other would be the point at the end of a line stretching directly into the screen from the mouse (various ways of doing this depending on how your prog works). The command should return what was collided with (I have assumed it takes a zero for the object number and passes back the object number collided with, just like the Object Collision command, the manual does not make this clear).

"Don`t try to engage my enthusiasm, I don`t have one"
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 17th Jul 2003 12:49
Sorry I just re-read you message and noted you are trying for a point on a matrix, which I admit would be more difficult and no simple method springs to mind.

"Don`t try to engage my enthusiasm, I don`t have one"
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 17th Jul 2003 13:04
look in the snippet section, there's a post who make it
it gives the coordinates of the mouse on a randomized matrix

"He will come...the voice from the outer world,
bringing the holy war, the Jihad, which will cleanse the Universe and bring us out of darkness."
JamesBlond
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Germany
Posted: 17th Jul 2003 15:16
Quote: "it gives the coordinates of the mouse on a randomized matrix"

actually he converted the matrix to an object, which works perfectly well, but might not be what everybody wants to have...

Smile and be happy, things could be worse!
So I smiled and was happy, and things got worse...
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 18th Jul 2003 03:49
I found that code and it seems like overkill. I think id like to write my own using a bullet fire style method (its just a map editor so it doesnt need to be lightning fast). Using a invisible bullet point would make it much easier to check collision with the matrix and objects alike (no converting back and forth).

However, like I said before, Im not sure how to offset the 'bullet' depending on the position of the mouse. ie if im firing like a normal bullet (from the center crosshair), id use the camera xyz position and the camera xyz angles. However, if the mouse is anywhere besides the dead center of the screen, what exactly do I have to do to offset the starting position and angle of the 'bullet'?

Thanks in advance

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 19th Jul 2003 03:39
Nobody has any idea? The problem is, one point/pixel on the 2d screen does NOT translate into 1 point in 3d space. Thus I cant figure out how youd offset a starting point in 3d space, based on the position of the 2d mouse.

Come on I know there must be some brilliant mind out there with the answer

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 19th Jul 2003 04:26
@AzureZeal

Upgrade 5 has PICK OBJECT and PICK SCREEN commands, these allow you to easily find out what object was picked by the user (to deal with matrixes, position a small object, eg a sphere at each point on the matrix). The PICK SCREEN command translates 2D co-ords to 3D.

spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 19th Jul 2003 04:34
I can't wait for U5. All bugs that I have encountered have been fixed in it. I just hope that all new commands are explained properly. The quick list of fixes that accompany each patch just don't explain in plain English what has been fixed and just confuse you with technical mumbo jumbo.

R Tape loading error
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 19th Jul 2003 08:15
Bah this azurezeal waits for no patches. I know I could write the code myself if I could just figure out how to calculate this ONE thing...

I need to translate the points at the far corners of the screen into points in 3d space. Im guessing this will have something to do with the fov of the camera... Surely somebody must know what this calculation would look like. Knowing the edge, and the center (camera x,y,z), ill be able to offset my bullet, and do my own custom "3d click check".

keeblerElf
23
Years of Service
User Offline
Joined: 11th Jun 2003
Location: United States
Posted: 19th Jul 2003 08:31
you could use small planes instead of pixels

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 19th Jul 2003 11:51
Hope there is lots of testing though

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 19th Jul 2003 12:14
Small planes instead of pixels? Because the 2d position will have to be gotten via the mouse position, I dont see how that would work. You still have to eventually make the jump from 2d pixel coord to 3d space.

Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 19th Jul 2003 14:07
Cool.... it seems like Patch 5 got a lot of new features. Does anybody know when is it realising? And how do we know the new commands added in patch 5?

Thanks!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
keeblerElf
23
Years of Service
User Offline
Joined: 11th Jun 2003
Location: United States
Posted: 19th Jul 2003 21:47
AzureZeal: No you wouldn't have to make the jump from 2d space to 3d space if you use small planes because darkbasic allows you to place the small plane anywhere in 3d space via the position object command

keeblerElf
23
Years of Service
User Offline
Joined: 11th Jun 2003
Location: United States
Posted: 19th Jul 2003 21:50
nevermind I get what your asking now. What you could do is based on what camera angle is at the time you would know whether you want the mouse to based on the x/y axis', the x/z axis', or the y/z axis'. I'll work on it for a bit and see if I can figure out how to do it based on what camera angle you have

keeblerElf
23
Years of Service
User Offline
Joined: 11th Jun 2003
Location: United States
Posted: 19th Jul 2003 21:54
You could have a hidden object at the center of the level or whatever else you are using and if the angle from the hidden object at the center of your level to the camera's position along the z axis is less that 45 degrees you could have the mouse movement correspond to the z axis and if it is greater than 45 degrees you could have the mouse movement correspond to the x/y axis. this would allow you to click anywhere in 3-space as long as the user has control over the camera.

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 20th Jul 2003 04:07
Lets not worry about angles right now. Lets assume the camera x angle and camera y angle = 0 (ie youre looking straight ahead). We know the center of the screen is camera position xyz(). Now all we have to do is solve this equation...

camera position y() + x = the top of the screen

Problem is to solve that equation you need to know either x or 'the top of the screen'. God only knows how youd figure that out...

I know ive played games before where you shot from the mouse cursor (although perhaps they were in 2d). You wouldnt think this would be so damn difficult...

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 20th Jul 2003 14:34
Surely there have to be some math geniuses out there. I know that using such a bullet fire method might not be as elegant as your standard angle/math click checks, but I really think it will get the job done fine.

So again, how can you calculate the edges of the screen in 3d space?

MiniMark
23
Years of Service
User Offline
Joined: 21st Mar 2003
Location: Australia
Posted: 20th Jul 2003 14:59
Dont know much about the programming protocols in DB but couldnt you make your mouse pointer into a plain with with a texture of a pointer on it then move that in 3d space. Use say hold right click to move along Z axis and use standard mouse for x and y? Then you dont have to play with the camera controls at all. Just a thought ????

There's no u in TEAM, so bugger off!!!
--Twin P4 Xeon 2.0 Ghz, GeForce Quadro4 XGL 128MB, 1Gb DDR RAM, 19" Flat Screen--
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 20th Jul 2003 15:46
I've just put together a U5 demo which lets you set the height of Matrix tiles by clicking and dragging.

Check the code snippets forum

JamesBlond
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Germany
Posted: 21st Jul 2003 00:43
Try this one. Have fun
http://www.darkbasicpro.com/apollo/view.php?t=13689&b=6

Smile and be happy, things could be worse!
So I smiled and was happy, and things got worse...
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 21st Jul 2003 04:13
I appreciate all the effort, but id really rather not have to wait for patch 5, and id also rather not use a system that only detects matrix position. The whole point of a bullet fire system was because it would work well with my own custom collision, allowing me to detect clicks on the matrix AND objects alike.

Id still like to figure out how to translate 2d mouse coords into 3d space. Hell lets assume I wanted to make a game where you shot bullets from the mouse cursor. It HAS to be possible. Just need a math genius to figure out HOW.

JamesBlond
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Germany
Posted: 21st Jul 2003 14:47
My code does convert 2d to 3d coordinates. ox#,oy# and oz# are the coordinates of a point in space wich is exactly r# units away from the camera and below the mouse cursor. You can use these coordinates and the camera coordinates to get a line along which you can travel until you hit the matrix or an object or do whatever you like.

Smile and be happy, things could be worse!
So I smiled and was happy, and things got worse...
Dmitry K
23
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 21st Jul 2003 16:50
Maybe this will help.
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 22nd Jul 2003 05:14
Wohoo thanks guys! Looks like this is what I need.

DMiTROS, your code is perfect, but I dont quite understand how/why it works. Can you/somebody please school me on the whole...
"
r=Make Matrix4(ViewMatrix)
r=Make Matrix4(ProjectionMatrix)
r=Make Vector3(Vector)
"
Ive never worked with vecotrs before. What the hell is a vector anyway? And how does that single line use move and position the bullet so perfectly, using only "vector"?

"
Position Object Bullet, Object Position X(Bullet)+X Vector3(Vector)*BulletStep#, Object Position Y(Bullet)+Y Vector3(Vector)*BulletStep#, Object Position Z(Bullet)+Z Vector3(Vector)*BulletStep#
"

EddieRay
23
Years of Service
User Offline
Joined: 28th Feb 2003
Location: USA
Posted: 22nd Jul 2003 06:53
By the way, I think Newletter #7 says the PICK OBJECT and stuff WILL be in update 5. Only helps if that's what you want to do tho' (click on a 3D object in a scene).

indi
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 22nd Jul 2003 09:32
it works and someones posted a working snippet in the snippets section modifying a matrix with mouseclicks

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 23rd Jul 2003 05:06
Im sure it works but I just dont want to wait for patch 5. Dimitros's code works PERFECT, I just dont understand the whole matrix vector part of the code. Id like to understand it rather than just blindly using it. Can anyone explain it?

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 26th Jul 2003 05:06
Still nobody can explain vecotrs? The db help files really sucked

Neophyte
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 26th Jul 2003 09:27
@AzureZeal

Geometrically speaking, vectors are imaginary lines. They usally appear written in the form of xyz coordinates like say (1,4,-6) though they can be 2D(x,y) or 4D(x,y,z,w).

But here in lies the problem though. When you see coordinates like (5,6) you tend to think of the point (5,6) and not the vector. The trick is to remember that a vector is a line and not a point. So how do you get a line out of (5,6)? Its simple. Imagine you have a triangle like so:



When someone says that a vector has a x coordinate of 5 imagine drawing the bottom of your triangle 5 units long like so:



and with a y coordinate 6 units long:



Now if you can imagine your triangle having a hypotenuse connecting the two then you just imagined your vector:



The same applies to 3D vectors(lets not get into 4D). Though I can't really "draw" it like with the previous example just imagine a line going into(or coming out of, whichever you prefer) the screen and instead of connecting the hypotenuse with the top of the 6 unit line connect it with the end of whatever line you just imagined(did that make sense?).

Now from a programmer's standpoint vectors are just arrays of numbers no different from any other array. The only thing that is special about them is that operations can be done to all of the numbers in the array in one command(like ADD VECTOR 2)rather than having to do the operation on each and every component one by one.

I hope that made sense and helped you out. Feel free to ask any questions about the parts where I might not have been so clear.

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 26th Jul 2003 11:31
Hmm so a vector is just a hypotonous from point 0,0,0 to point x,y,z (or 0,0 to x,y in the case of 2d)? And you say a vector is setup like an array, containing the coords for all the points along that hypotonous/line? Starting to make a little sense, but I dont understand how you "declare" and access such an array. I tryed playing around with all the different vector related commands, and none of them seemed to work for me (most likely I just wasnt using them properly). Can you write a simple program demonstrating the basics? Dimitros's code confuses the hell out of me with all the matrix stuff. I need to get a good solid foundation on vectors before I dive any deeper into 3d maths.

Thanks in advance

Furiousuk
23
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 26th Jul 2003 12:29
There's a lot of information on vectors at GameTutorials.com. The examples are all in C++/OpenGL but vector theory is the same no matter what language you're using.
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 26th Jul 2003 21:05
I did a search through that sight and couldnt find the parts about vectors. Do you remember what section they were under? I looked through the directx and opengl tutorials. Im still having trouble understanding how vectors would be used in a simple basic program.

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 28th Jul 2003 18:53
Can anyone post a example of how youd use JUST a vector in a simple program? I still dont understand how knowing the points along a line/hypotonous would be used.

jn_omega
22
Years of Service
User Offline
Joined: 29th Jul 2003
Location:
Posted: 29th Jul 2003 11:16
a vector isnt an array, its just a line composed of three components like an (r,g,b) value. except this is an (x,y,z) value denoting the end position of a vector starting from (0,0,0). vectors are used a lot in physics for direction and velocity of movement or such. as for how it works with this i dunno.

AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 29th Jul 2003 17:58
So when neo said "Now from a programmer's standpoint vectors are just arrays of numbers no different from any other array" he didnt mean they hold data like arrays, but rather the just kinda 'look' like arrays? So a vector DOESNT actually hold any data... how in gods name do you make use of it then?

Furiousuk
23
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 3rd Aug 2003 20:33
From 'Mathematics for 3D Game Programming and Computer Graphics':
Quote: "Vectors are used to represent points in space such as the locations of objects in a game or the vertices of a triangle mesh. They are also used to represent spatial directions such as the orientation of the camera or the surface normals of a triangular mesh."


Vector math is a tough subject to understand, a subject which takes a while to grasp. DarkBASIC hides the vector math, which is one reason its so popular. Try renting a book from the library or searching on the internet for Vector Math, you can't be a good 3D programmer without at least a basic understanding of the theory and application.

Try downloading the Tutorials/OpenGL/Camera tutorial from Gametutorials.com and read through Camera.cpp, it'll open fine with notepad. There's an example of Vectors at the bottom. If you know C++ at all try to follow through the code and see how they are used to control the camera. It's basically exactly the same as the DarkBASIC camera controls work.
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 3rd Aug 2003 20:37
Here are the functions I use. You get the X and Z 3d co-ords from a 2d position. Requires one small hidden object (number 999). This has been lifted from my game so there may be bits that aren't needed in yours.



I only use them in an RTS viewpoint (raised and slightly down) - facing flat along the 'floor' will cause considerable lag.

You are the th person to view this signature.
GRAVITY: I fought the law but the law won
iaretony
23
Years of Service
User Offline
Joined: 6th Jun 2003
Location:
Posted: 4th Aug 2003 22:32
I like the following as a definition of vector:

Vector: a mathematical entity with a direction and a magnitude.

Having a direction means that it is pointing somewhere. Having a magnitude means that it has some length.

Lets talk about 2D vectors as the concepts are the same.

(10,10)

This defines a 2D vector that begins at the origin, and terminates at 10, 10. Having said that, this vector may in fact be located anywhere. Since a vector does not specify a location (like a point), it need only specify it's endpoint to convey magnitude and direction. For example, my physics simulator actually uses two vectors for each object. One of the vectors simply holds the current position (X,Y) of the object, the other vector defines a direction and magnitude AWAY from the first point. This vector defines the speed and direction of an actor in the simulation.

The best part about vectors are the operations that can be performed on them. You can use the dot product of two vectors to determine the angle difference between them, and for 3D vectors the cross product of 2 vectors yields a 3'rd vector that it perpendicular to the first two.

Think about this. If I have a triangle in 3D space, and I'm trying to figure out how much light is hitting it (from the lightsource), I can do the following:

Treat two side of the triangle as vectors and take the cross product of these. This will yield a perpendular vector (called a normal)... The dot product of this vector and the lightsource vector will tell me the angle between them. This value can be used to scale a light value.

Cool huh!

Tony

Login to post a reply

Server time is: 2026-07-23 03:45:10
Your offset time is: 2026-07-23 03:45:10