About Store Forum Documentation Contact



Post Reply 
[Solved] Dof with Callback
Author Message
Harry Offline
Member

Post: #1
[Solved] Dof with Callback
I'm back with new thread grin

I try to put in my project dof effect using PhysHitCallback. But I had same errors. Yesterday I thought about it and actually code is look like this:

Code:
Bool Dof::hit(PhysHit &phys_hit)
{
   if(Chr *chr=CAST(Chr,phys_hit.obj))
   {
      if(Player *plr=CAST(Player,phys_hit.obj))
      {
      }else
      {
               ray_hit    =true;
            ray_hit_pos=phys_hit.plane.p;
            new_z      =phys_hit.dist; //set new z focus to ray hit distance
      }
   }else if(!ray_hit) // jesli jeszcze nie trafil w ogole
   {
      ray_hit    =true;
      ray_hit_pos=phys_hit.plane.p;
      new_z      =phys_hit.dist; //set new z focus to ray hit distance
   }
   return true; // zawsze kontynuuj
}
void ADoF()
{
   Vec pos,dir;
   Dof adof;

   if(crossDraw)
   {
      if(Ms.hidden())
      {
         pos=Cam.matrix.pos;
         dir=Cam.matrix.z;
      }else
      {
         ScreenToPosDir(Ms.pos,pos,dir);
      }

      Physics.ray(pos,dir*ViewportActive.range,adof); // cast a ray from camera and check if it hits something

      // set new depth of field z focus
      D.dofPzr(1,LerpTime(D.dofZ(),adof.new_z,0.001),18);
   }else D.dofPzr(0,0,0);
}

Everything will be ok but I don't know where I can put this line

Code:
new_z =ViewportActive.range;

which change z parametr when Physics.ray hits nothing. Can anybody help me?
(This post was last modified: 02-14-2011 11:22 AM by Harry.)
10-15-2009 08:28 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Dof with Callback
please try something like this

Code:
struct Dof : *Callback*
{
    Bool ray_hit;
    Vec ray_hit_pos;
    Flt new_z;

   Dof(){ray_hit=false; new_z=ViewportActive.range;} // here you can optionally set 'ray_hit_pos' too if you use it

Bool hit(PhysHit &phys_hit)
{
    if(Player *plr=CAST(Player,phys_hit.obj))
    {
    }else
   {
      if(!ray_hit || phys_hit.dist<new_z) // if haven't hit yet, or new hit is closer than the previous one
     {
        ray_hit    =true;
        ray_hit_pos=phys_hit.plane.p;
        new_z      =phys_hit.dist; //set new z focus to ray hit distance
     }
   }
   return true; // always continue
}
10-15-2009 08:49 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #3
RE: Dof with Callback
I use this code but i have sth like this http://img93.imageshack.us/img93/8969/scrsh2k.jpg

All the time. But when I delete this || phys_hit.dist<new_z everything is ok except objects Chr, because ray don't find them or sth like this. So in older code I have

Code:
if(Chr *chr=CAST(Chr,phys_hit.obj))
   {
      if(Player *plr=CAST(Player,phys_hit.obj))
      {
      }else
....

I put new_z=ViewportActive.range; in constructor as you wrote but nothing happens.
10-15-2009 09:21 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #4
RE: Dof with Callback
please try using debugging in your callback function, and after it
also please check Physics.draw if you see that all actors are setup correctly
10-15-2009 09:37 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #5
RE: Dof with Callback
I debugg this a lot of times and always I see that in Bool Dof::hit(PhysHit &phys_hit) new_z is changing correct but when application go forward and is after ray testing new_z is automatically set to 0. I use only one new_z variable.
10-15-2009 10:01 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #6
RE: Dof with Callback
then check what actor makes the collision which results in "0" value
10-15-2009 10:14 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #7
RE: Dof with Callback
Now I saw sth strange. On the first time phys_dist value is for example 11 but on the second time it's equal 0 and again 11 and 0 and it's all the time.
10-15-2009 10:34 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #8
RE: Dof with Callback
please check to what object points the phys_hit.obj when phys_hit.dist is equal to 0
10-16-2009 12:06 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #9
RE: Dof with Callback
At least! I fixed this grin I made stupid mistake. I write it here because maybe it will be useful for someone:

Code:
void Player::create(Game::ObjParams &obj)
{
    ctrl.createCapsule(0.5,2.1,pos());

    __super::create(obj);
}

Before I had:

Code:
void Player::create(Game::ObjParams &obj)
{
    __super::create(obj);

    ctrl.createCapsule(0.5,2.1,pos());
}

EDIT: I tried this in another model abd now this capsule isn't working. How can I fix this pfft ??
(This post was last modified: 10-28-2009 10:18 PM by Harry.)
10-28-2009 10:01 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #10
RE: Dof with Callback
if you want a custom sized capsule then you should create a physical body (check documentation\creating games\importing character meshes)
10-28-2009 11:27 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #11
RE: Dof with Callback
Yeah grin It works fine. Thanks a lot.
10-29-2009 02:13 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply