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.

AppGameKit Classic Chat / How to draw a line from point x,y,z to x2,y2,z2 , ie. DrawLine() but for 3D ????

Author
Message
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 4th Dec 2018 16:31

I'm basically trying to debug a raycasting issue that's fairly demanding in terms of performance (I'm trying to make some ants avoid eachother, there are thousands), but to be honest I can't really tell whether the rays shoot in the right direction, change when the angle of the ant is changing and so on. So I'd like to draw some kind of line to see where the ray tracing goes.

Any ideas, tips or tricks people want to share??

Also, I did notice raycasting loves to return the very object it spawned from. I feel AGK2 really needs some kind of flag to always ignore the object where tracing started. I know I can check the HitID and ignore the first object that way, but to me it always came across a bit weird it doesn't ignore that when the idea is 'collision check with another object' and virtually never itself, right?
puzzler2018
User Banned
Posted: 4th Dec 2018 17:18 Edited at: 4th Dec 2018 17:20
I did a 3D Line function which accepts

x1,y1,z1,x2,y2,z2

some time ago hidden in some of my thread somewhere - for the life of me, i cannot find it, once i do, ill let you know it

I did a rotation box made of drawline commands


can anyone remeber that bit of code and which thread it was at all?
puzzler2018
User Banned
Posted: 4th Dec 2018 17:26
Found it - it was in the Coding Train Conversions thread



Hope this is what your looking for
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 4th Dec 2018 17:45
Thanks so much! yes that does look very useful! I will have to do some experiments to see if it helps with my ray tracing debugging
puzzler2018
User Banned
Posted: 4th Dec 2018 17:48
Your welcome and happy it will come in use. I never thought to do debugging with it though, awesome
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 4th Dec 2018 21:11
You could also use GetScreenXFrom3D() and GetScreenYFrom3D()
GaborD
6
Years of Service
User Offline
Joined: 3rd Dec 2017
Location:
Posted: 5th Dec 2018 12:07 Edited at: 5th Dec 2018 12:22
You could go with a 3D quad and just send x1,y1,z1 and x2,y2,z2 to a shader that is applied to it and set the vertex positions accordingly.
Based on the uv coords it's easy to know which vertex belongs to which end.
You can also calculate the perpendicular vector to the plane that the view vector and the line direction build and use that to add thickness to the line object. This way the thickness offset will always rotate with your cam view and you don't get ultra thin lines from certain angles.
The thickness is ofcourse set in 3D world space, so it will vary with the perspective (a true 3D line object). But if you are debugging linepicks that's a good thing I guess, makes it easier to immediately see where the line is in 3D space.
Sidenote: If you want to have non 3D distance reliant thickness, you can move the thickness part to after the ViewProj transform. If you take the line direction to clip space too, it should be simple to do a 90 degree 2D rotation to get the thickness offset direction.

Here is a simple shader that you can use as starting point. Make sure the quad you use has UVs set to 0,0 to 1,1. (so basically what any 3D app will set as default anyway)

Vertex shader:

Basically, the first line in the main vertex shader function sets each pair of vertices to the appropiate end points of the line, then line 2 adds some thickness.


For the pixel shader you can just use the simplest pixel shader of all times and write out a color of your choice (which can also be set from AppGameKit code)

To set the end points and thickness from AGK:
SetShaderConstantByName(shaderID, "pos1", x1, y1, z1, 0)
SetShaderConstantByName(shaderID, "pos2", x2, y2, z2, 0)
SetShaderConstantByName(shaderID, "thickness", thickness, 0,0,0)

I just quickly threw it together, could be improved a lot!
But it seems to work, I added it to a random test scene and had no issues. (screens attached)

Attachments

Login to view attachments
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 5th Dec 2018 17:36
Nice! Seems like that could easily be adapted to something like weapon / bullet trails also
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 16th Jan 2019 00:16
Thanks GaborD, by the way, amazing scene with the mushroom there!

Login to post a reply

Server time is: 2024-04-16 16:56:45
Your offset time is: 2024-04-16 16:56:45