|
1 registered members (Grant),
999
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
get the point where a line crosses an imaginary plane?
#381016
08/23/11 13:48
08/23/11 13:48
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
OP
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
Hi, When i have my mousecursor at the screen. I can use the direction to send a trace. But how can i determine if my line cuts a plane? For this specific situation: Iam looking at my surface made out of different cubes(atm). Now i need to calculate which cube is below my cursor to select it. Since i might consider using a single mesh later, i cannot use something like SHOOT. i need to calculate the point where my cursor trace hits the same plane as my surface. Bets ist, if its entity independend. Maybe someone has an idea? EDIT: since all of my blocks are aligned on my grid, i just need the global position to calculate the required block.
Last edited by Rackscha; 08/23/11 13:51.
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: get the point where a line crosses an imaginary plane?
[Re: Rackscha]
#381021
08/23/11 14:12
08/23/11 14:12
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
hit.x hit.y hit.z gives world coordinates of last c_trace
Last edited by Quad; 08/23/11 14:13.
3333333333
|
|
|
Re: get the point where a line crosses an imaginary plane?
[Re: Quad]
#381029
08/23/11 14:37
08/23/11 14:37
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
OP
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
mh, okay. i'll try that one. But an entity independend solution is still better. Imagine i remove one of those blocks, but still need to be able to select the space of this block. With a trace it would go thorugh the empty block(s). So PlaneIntersection seems more sufficient.
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: get the point where a line crosses an imaginary plane?
[Re: Pappenheimer]
#381042
08/23/11 15:37
08/23/11 15:37
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
OP
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
still doing something wrong.
Is it correct that the plane normal is (0,0,1) for intersecting with a xy plane? How do i correctly send the line from the mouse straight into the 3dspace. Have problems with mouse_dir3d etc (yes setting mousepos to mouse_cursor)
and is the origina of the plane correct if (0,0,0) ?
Maybe someone can help me a bit. My brain is cooking here at 30 dgree celcius >.<
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: get the point where a line crosses an imaginary plane?
[Re: Rackscha]
#381052
08/23/11 17:13
08/23/11 17:13
|
Joined: May 2005
Posts: 2,713 Lübeck
Slin
Expert
|
Expert
Joined: May 2005
Posts: 2,713
Lübeck
|
vec_for_screen() projects your vector into your world, if you just have the xy plane as plane, your normal is 0, 0, 1 and 0, 0, h is a good origin. With that knowledge you can build the HNF for the plane, which is something like: vec_for_screen(vector(0, 0, 1), camera) - camera.xyz (you will have to use some temp vector and vec_substract or something like that) gives you the direction of your line and camera.xyz is a position on it. So as a next step you have to enter your cameras position as v into the hnf: After this, a is the cameras distance to the plane. If you now normalize your direction, multiply it with a/z and add the cameras position, you´ve got your point:
mousedir*((camera.z-h)/mousedir.z)+camera.xyz = position
It is a bit more tricky with an arbitary normal, but the approach is basicly the same and this should already do it for your example.
|
|
|
Re: get the point where a line crosses an imaginary plane?
[Re: Slin]
#381060
08/23/11 17:44
08/23/11 17:44
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
OP
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
thanks, i'll try that
edit: what is h?
edit2: ah dump, h is my z distance to the plane >.<
Last edited by Rackscha; 08/23/11 17:52.
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: get the point where a line crosses an imaginary plane?
[Re: Slin]
#381063
08/23/11 18:40
08/23/11 18:40
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
OP
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
mh seems something is still wrong here. my point always ends up with z > 500.
Sorry to ask, but can you deliver a full example? something is absolutely wrong here >.<
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: get the point where a line crosses an imaginary plane?
[Re: Rackscha]
#381075
08/23/11 22:29
08/23/11 22:29
|
Joined: Feb 2011
Posts: 135
Myrkling
Member
|
Member
Joined: Feb 2011
Posts: 135
|
I planned to replace the additional vector functions bit by bit with smaller and clearer code snippets. This seems to be the right occasion to continue this plan. Here is the new line-plane intersection test: http://www.opserver.de/wiki/index.php/Plane-Line_IntersectionYou can use it like that:
#include <acknex.h>
<<<INCLUDE LINE-PLANE INTERSECTION TEST CODE HERE>>>
void main()
{
level_load(NULL);
mouse_mode = 4;
vec_set(camera.x, vector(-200,0,300));
camera.tilt = -45;
// Create a simple floor.
ENTITY *cube = ent_create(CUBE_MDL, NULLVECTOR, NULL);
cube.z -= cube.max_z;
vec_set(cube.scale_x, vector(8,8,1));
while(1)
{
VECTOR to;
vec_set(to,mouse_dir3d);
vec_add(to,mouse_pos3d);
// Get the intersection between the mouse ray and the floor.
VECTOR *ip = get_line_plane_intersection(mouse_pos3d, to, NULLVECTOR,
vector(0,0,1), NULL);
if (ip) // Draw intersection point.
draw_point3d(ip, COLOR_RED, 100, 6);
wait(1);
}
}
Just insert the intersection test code and compile it to see it in action.
|
|
|
|