Jump to content


Photo

is a model blocking the sight of view?


  • Please log in to reply
15 replies to this topic

#1 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 08 February 2012 - 10:59 PM

Hi GMC,
This is something that really bothers me and i couldn't even think of a lead to solve it,
Is it possible to check if a model is blocking the sight of view?

The idea is to lower the models transparency once it is blocking the view.

Any lead would be greatly appreciated.
Thanks.
  • 0

#2 M_I_Soft

M_I_Soft

    GMC Member

  • GMC Member
  • 198 posts
  • Version:GM8

Posted 09 February 2012 - 12:05 AM

You could assign a sprite mask to be the same as the model's footprint and use collision line to do the line of sight checking or if you want the exact dimensions including the z values then have a search for p3dc dll as that works on full colision models and has raycasting built in too.
All depends on what sort of speed you'll need and how complex your collision environment is.
  • 0

#3 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 09 February 2012 - 12:18 AM

You can try making a frustum model for you camera and check collisions on it using p3dc.
  • 0

#4 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 09 February 2012 - 01:37 AM

Thanks for the comments guys, but :
1. I rather not use DLL's.
2. Sprite mask wont work because the projection changes alot.

Lets make it simplier, how can I calculate the Z height of a model?
Even with ray casting, method doesn't really matters.

Thanks again.
  • 0

#5 Spikehead777

Spikehead777

    GMC Member

  • GMC Member
  • 485 posts
  • Version:GM:Studio

Posted 09 February 2012 - 04:27 AM

Here's an idea, assuming you're using a 3rd-person view.

First, you need two lists. Next, insert all of your models that you want the effect to happen to in the first list. You'll cast a ray from the camera to your player. If the ray collides with any of the models, remove the models from the first list and add them to the second.

Now, you'll draw all of the models in the first list, along with your other models like players, items, enemies, and such. Then, you'll exploit GM's z-buffer by drawing a 3D rectangle transformed to be in front of the camera. The 3D rectangle must have a special texture on it. Basically, the texture consists of the background, which has an alpha value of 0. Then, you'll have a circle with an alpha value of 1.

Finally, you'll draw all of the models in the second list. If all goes well, you'll have a circular section cut out of the models in the way of the view of your player.
  • 0

#6 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 09 February 2012 - 02:10 PM

By blocking sight of view you need to specify what blocking means. If you mean blocking as visible to the camera then just test if it is in the viewing frustum (look up view frustum culling) If you mean blocking the view as in blocking a certain point on the screen then you need to do raycasting to see if that point is blocked. (use Yourself's 2d to 3d script for the point on the screen to make the ray)
  • 0

#7 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 09 February 2012 - 03:37 PM

@ Spikehead777
The question is how to detect if a model is standing between the camera and the target, not how to make a model visible, but thanks anyways.

@ hit172
Using Yourself's scripts sounds intresting, maby using 3d to 2d will get me the result I'm looking, need to test it further.
Thanks for the idea.

Edit:
After I studied and tested Yourself's scripts I went lost again, I do understand the scripts but don't understand how am I suppose to ray cast.
The Rays need to look for somekind of collision, how am I suppose to collide with a model with no built in functions to return info about 3d shapes?
I thought the scripts might give an answer to that but unfortunatly it didn't.

Edited by zehevi, 09 February 2012 - 04:57 PM.

  • 0

#8 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 10 February 2012 - 12:04 PM

@ Robert Colton
Thanks for your comment but again, this is not the problem and I know how to ray cast,
the problem lays in the fact that we are talking about a Model not an Object or a sprite,
because GM don't have any build in function to regain the size or position of a model in 2d or 3d enviroment I cannot tell if this model is blocking my sight of view (Model, NOT object).

Quick illustration:
Posted Image
In this case, the model should be invisible.
  • 0

#9 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 10 February 2012 - 06:35 PM

@ Robert Colton
This method would work but the only obstacle is using models created by other people.
But this is surely an option, or atleast a lead. Thanks.
  • 0

#10 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 10 February 2012 - 09:15 PM

I don't use external models, all my models are converted into GML.
And if you mean running manually through the script line then it is nearly impossible to it with 2k poly model, which means 2k lines.
  • 0

#11 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 13 February 2012 - 11:28 PM

Well if you wrote you own script that loads d3d models, you could also run through and check each points distance to the other points and find which two points are furthest apart to give you an approximation of size.

Writing your own script to load models is going to be extremely slow in pure GML. Try saving your models as a gm file (d3d_model_save) with an accompanying file that stores things like the textures to be loaded by the game and bounding box which can then be used to test if the model is in the screen (just test the 4 points of the bounding box with the frustum clipping formula) This is probably the best way to do what you want in GML without being horribly slow.
Check this out for bounding box frustum culling http://www.cescg.org...inek/index.html
If you wanted to get fancy then you could make a rough outline of your model with boxes and save them with the accompanying file and test those boxes instead of one overall bounding box.
  • 0

#12 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 14 February 2012 - 12:18 AM

Yep there we go an even better way to estimate, I'd say his solution is about as good as close as you can get and is generally the solution used by most game engines. And thank you for that link because I was also wanting to look for a frustum culling extension. :thumbsup:

Ohh and I also did not mean turn it into a script model I meant your own script loader, which I know is slower Mr. Hit172, but obj loading scripts are not that slow either. And you could do this without actually building the model just looking for the furthest points, etc. to approximate dimensions. So it would be slightly quicker than loading a model, in theory anway.

Any GML at all is going to be slower than the built in functions. The fastest way to load an obj file would be to read the entire file into memory and then process it because batch reads are faster than individual ones. Unless the file reading scripts have been updated in 8.1.whatever the heck it is now, it will still be much slower on larger models than the built in functions... They just need to add the ability to then edit the loaded model/get the location of the vertices (like a d3d_model_get_vertex_x/y/z so we could then do calculations off of that) Always remember, GML is always slower than everything else.

Edit: If you are looking for more intense 3d collisions then try looking at the source for pc3d and try porting some of it to GML (its pretty messy though)

Edited by hit172, 14 February 2012 - 12:31 AM.

  • 0

#13 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 14 February 2012 - 05:03 PM

Hit172, what you are refering to is index/vertex buffers and it is quite ridiculous GM has not had them yet, all it requires is a simple d3d_model_vertex_buffer_set(modelid, index of vertice) or something similar. It would allow us to actually do animations properly and etc, etc, and hopefully GM 9 :smile:

And I think you misunderstood what I was saying, to load a d3d model using built in functions would be FASTER than using your own script to interpret the model file and also FASTER than using your own script to interpret an obj model but both methods of using a script would be just as fast and I was using this as an example of how it would not be that slow for him to make a script that does this but just tests the size of the model. However it would be even quicker if one were to go through and just look at the dimensions of the model and not rebuild it, it would actually be quite quick without an extension an faster than loading the model if it were in obj format. And try doing what you mentioned to an obj file without using an extension...


Why not just store the bounding box and other things needed (like textures and collision primitives) in a separate file which would be smaller and easier to parse in GML, instead of processing a d3d model and find the bounds by using the max values of the vertices. Both would work but I don't know what would be faster.

This has become quite offtopic.
  • 1

#14 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 14 February 2012 - 07:20 PM

Thanks for the comments guys,
the global idea I've got from you is nice but yet, a function as 'hit172' suggested (d3d_model_get_vertex_x/y/z) does not exists.

How can this be achieved without such a crucial function?
  • 0

#15 zehevi

zehevi

    GMC Member

  • GMC Member
  • 732 posts
  • Version:GM:Studio

Posted 14 February 2012 - 10:32 PM

The only way to implement the method he mentioned was like I said using index/vertex buffers which GM does not have and should have had a long time ago so that one can manipulate and inperpret model data on the fly.


So a DLL is an integral part of the equation.
I guess I'll try to use an external model editor to measure the dimentions of my models.

Thanks for the help guys.
  • 0

#16 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 15 February 2012 - 12:00 PM

The only way to implement the method he mentioned was like I said using index/vertex buffers which GM does not have and should have had a long time ago so that one can manipulate and inperpret model data on the fly.

Yes a dll is pretty much required to do this properly and without some really ugly math that game maker would take forever to do and completely unplayable (unless you want to thread it and run it as a separate thread at like 2~3 fps)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users