How to know if the object is behind an object?

This is a discussion on How to know if the object is behind an object? within the Game Programming forums, part of the General Programming Boards category; Does raycasting suited on this? How? I need the ray to be perpendicular to the camera. Meaning it should only ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    64

    How to know if the object is behind an object?

    Does raycasting suited on this?

    How? I need the ray to be perpendicular to the camera. Meaning it should only cast a straight line directly to the camera so that I know if it is behind or now.

    Any idea how to it efficiently?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    The ZBuffer normally solves this problem. However you can do occlusion testing as well. There are several ways to do occlusion culling and some approaches depend on your API of choice.

    If this is for 3D picking then you can usually create a list of objects that were hit by casting your ray into 3 space and then pick the closest one to the camera.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    64
    I'm using Ogre3d. I tried many things. I don't know how to get the origin of the ray and test if it is behind the object.

    I'm confused. I tried to google it but don't get a pretty good results.

    Yes the 3D picking is already solve by getting the cameratoray function in ogre3d then cast a ray from that mouse coordinates.

    My problem is if I should cast a ray or a plane or whatever it should be..

    Yes ZBuffer solves it in opengl but in ogre I don't know how to do it. They said I should cast a ray, but where should be the origin? It should not be a center of the window because it doesn't work right.

    Sorry if my english is not so good. I hope you understand what I mean

    Thank you
    Sarah

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I don't know how to get the origin of the ray and test if it is behind the object.
    If this is for 3D picking the origin of the ray is the click point. You must convert it to a 3D ray.

    My problem is if I should cast a ray or a plane or whatever it should be..
    Not sure I understand this. I've never heard of casting a plane into 3D space.

    Tell me what it is you are trying to do and then I will have a baseline from which to help you. If I don't understand the problem I can't very well help you.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    64
    I have a tree and an object in 3D world. The projection is orthographic and the camera is ( 0, 100, 0 ) facing the main terrain isometrically. (I don't know if this is the right word but it looks like isometric. I'm not the main developer on this project so I can't give you some picture because I'm not in his house right now.)

    Here's what I'm trying to do, I have many trees and building. I want when my character is behind these static objects, they become transparent so that my character become visible to the user.

    I tried casting a ray that from the camera but it has some flaws. check the pic below.

    http://img580.imageshack.us/img580/5099/44089570.png


    So I tried to cast a ray from the target but I don't know where should it headed/direction because the camera has only a certain point(the center of the screen).

    http://img580.imageshack.us/img580/6789/35378468.png

    Red: Ray
    Black: Building/Trees
    Yellow: Character

    Thank you
    Sarah
    Last edited by sarah22; 05-01-2010 at 11:16 AM.

  6. #6
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    I don't use Ogre very much. But here's an idea:
    Code:
    1)Make a ray
    2)Set the origin to camera x, y, z
    3)Set the direction to the angle from the camera to the character
         *does the vector for direction have to be a unit vector? I don't know.
         *if so, divide each part by the magnitude of the vector to get a unit vector
    4)Test for collisions with the ray
         *if the collision has a distance less than the distance from the camera to the character then there is something in front of the character
         *keep checking until you get to the character (in case multiple buildings are between the two)
    Consider this post signed

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    64
    I don't get what you mean in #3..

    Is it I'm solving the arctan() ? But that just give me an angle? The api here states that I should put a vector there and those vector are in Float. So what should I do?

    OGRE: Ogre::Ray Class Reference - OGRE Documentation

    OGRE: Ogre::Vector3 Class Reference - OGRE Documentation

    I'm sorry but I didn't understand what you mean there.

    Thank you very much for the help
    Sarah

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    64
    Oh, I solved this one already. What I did was this.

    First, I subtract the camera position and camera target to get a vector then normalized it and plugged it on the ray as the direction and the origin will be the target/object.

    Resulting a ray casted from the target which is always perpendicular to the screen/near/camera plane or whatever you call it. But if you know what you call it. tell me. lol

    Thank you
    Sarah

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using this as synchronization object
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 07:49 AM
  2. synchronization object choosing
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 04:33 AM
  3. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  5. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21