Radioactive-Software Radioactive-Software
Forum to discuss Radioactive-Software Products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

is picking used to shoot the enemys?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Radioactive-Software Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Anddos
Jehovah's Witness


Joined: 24 May 2009
Posts: 29

PostPosted: Tue Jun 02, 2009 12:07 pm    Post subject: is picking used to shoot the enemys? Reply with quote

i am a newbie directx programmer and looking at how the mouse cursor becomes the aim in a fps type game , lets say you click on the mesh and it intersects that would mean the enemy looses health right , how would you handle things like blood on the vertices thats clicked ,
Back to top
View user's profile Send private message
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Tue Jun 02, 2009 12:41 pm    Post subject: Re: is picking used to shoot the enemys? Reply with quote

Anddos wrote:
i am a newbie directx programmer and looking at how the mouse cursor becomes the aim in a fps type game , lets say you click on the mesh and it intersects that would mean the enemy looses health right , how would you handle things like blood on the vertices thats clicked ,


You'd use a decal system with the returned position from the picking / raycast system.
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
Anddos
Jehovah's Witness


Joined: 24 May 2009
Posts: 29

PostPosted: Tue Jun 02, 2009 2:42 pm    Post subject: Reply with quote

do you have any info on decals with directx?,
Back to top
View user's profile Send private message
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Tue Jun 02, 2009 6:16 pm    Post subject: Reply with quote

Anddos wrote:
do you have any info on decals with directx?,


Just duplicate the triangles that intersect with the decal's axis aligned bounding box, and project the decal's texture onto the duplicated tris.
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
Anddos
Jehovah's Witness


Joined: 24 May 2009
Posts: 29

PostPosted: Tue Jun 02, 2009 6:39 pm    Post subject: Reply with quote

here is my pick function ,i think its not working properly
do you see anything i am doing wrong ,thanks

void Pick(D3DXMATRIX View,D3DXMATRIX matProj)
{
POINT point;
RECT rect;
GetCursorPos(&point);

HWND D3DWin = FindWindow(NULL,"Our Direct3D Program");
ScreenToClient(D3DWin,&point);
GetWindowRect(D3DWin,&rect);

D3DXVECTOR3 v;
v.x = ( ( ( 2.0f * point.x ) / rect.right ) - 1 ) / matProj._11;
v.y = -( ( ( 2.0f * point.y ) / rect.bottom ) - 1 ) / matProj._22;
v.z = 1.0f;

D3DXMATRIX m;
D3DXVECTOR3 rayOrigin,rayDir;

D3DXMatrixInverse( &m, NULL, &View );

// Transform the screen space pick ray into 3D space
rayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31;
rayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32;
rayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33;

rayOrigin.x = m._41;
rayOrigin.y = m._42;
rayOrigin.z = m._43;

D3DXMATRIX matInverse;
D3DXMATRIX matWorld;
d3ddev->GetTransform(D3DTS_WORLD,&matWorld);

D3DXMatrixInverse(&matInverse,NULL,&matWorld);
// Transform ray origin and direction by inv matrix
D3DXVECTOR3 rayObjOrigin,rayObjDirection;
D3DXVec3TransformCoord(&rayObjOrigin,&rayOrigin,&matInverse);
D3DXVec3TransformNormal(&rayObjDirection,&rayDir,&matInverse);
D3DXVec3Normalize(&rayObjDirection,&rayObjDirection);


//this below was another method from my book
/*
float w = (float)rect.right;
float h = (float)rect.bottom;

float x = (2.0f*point.x/w - 1.0f) / matProj(0,0);
float y = (-2.0f*point.y/h + 1.0f) / matProj(1,1);

D3DXVECTOR3 origin(0.0f,0.0f,0.0f);
D3DXVECTOR3 dir(x,y,1.0f);

D3DXMATRIX invView;
D3DXMatrixInverse(&invView,0,&View);

D3DXVECTOR3 originW;
D3DXVECTOR3 dirW;
D3DXVec3TransformCoord(&originW, &origin,&invView);
D3DXVec3TransformNormal(&dirW,&dir,&invView);
D3DXVec3Normalize(&dirW,&dirW);
*/

BOOL hit = 0;
DWORD faceIndex = -1;
float u = 0.0f;
float v = 0.0f;
float dist = 0.0f;
DWORD numHits = 0;

D3DXIntersect(meshTeapot,&rayObjOrigin, &rayObjDirection,&hit,&faceIndex,&u,&v,&dist,NULL,&numHits);

if(hit)
{
MessageBox(NULL,"hit","",0);
}



}
Back to top
View user's profile Send private message
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Tue Jun 02, 2009 8:10 pm    Post subject: Reply with quote

It could be a million things, you should debug it and make sure the values look right.

Also try rendering the picking rays and the geometry.

There is a DirectX picking sample in the old SDKs.
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
Anddos
Jehovah's Witness


Joined: 24 May 2009
Posts: 29

PostPosted: Tue Jun 02, 2009 8:58 pm    Post subject: Reply with quote

so does the code look ok to you?
Back to top
View user's profile Send private message
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Tue Jun 02, 2009 9:06 pm    Post subject: Reply with quote

Anddos wrote:
so does the code look ok to you?


I've just spent the last 15 hours coding, I've got a lot of stuff to do, don't have time to debug logic errors your code. Yea it looks like the code from the SDK sample...so trace your steps back and find out where it got messed up. It could be any number of factors outside this code [ does it even compile btw? ]. Anyways, for instance, the model could be loaded wrong, matrices could be setup wrong, etc, I don't know...I'm not going to spend time looking over a code fragment for possible errors. Surprised

I gave some tips in my last post that helped me many years ago, when I was debugging/writing my raycasting systems...DEBUG/VISUALIZE the system. Come back with more info and I can help point you in the right direction.
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Radioactive-Software Forum Index -> Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group