MP: View matrix problem

All information about Magic Particles: news, question, comments, etc.

MP: View matrix problem

Postby NDark » Wed Jun 20, 2012 11:00 am

hi,

I'm trying the magic particle wrapper for directX and integrate with my system.
Because the D3D device is create myself, therefore , I inherit MP_Device_WRAP and pass the device into it.

Currently, I load the resource "example3d.ptc" along with dx_wrapper project , so far I can see the "particle" , somehow it's locate with my camera, I can only see some part of this particle ( 'cause it keep rotates itself )

Therefore, I'm trying sync. the view matrix of MP and my system, but I fail.
what I do is

1. each loop update, I wrap my view matrix to D3DXMATRIX like this:
Code: Select all
      GlueMatrix d3dwrap( viewMatrix ) ;
      D3DXMATRIX view = d3dwrap ;
      Magic_SetViewMatrix((MAGIC_MATRIX*)&view);

2. render some my stuff
3. update and render MP like this
Code: Select all
         MP_Manager& MP=MP_Manager::GetInstance();
         MP.UpdateByTimer() ;
         MP.Render();


However, no matter how I change the camera position, and confirm the matrix do change, the particle still follows my camera. ( can't see the whole particle )

Is there something I go wrong?
Or magic particle will alter/reset my d3d device matrix ?

NDark
NDark
 
Posts: 6
Joined: Wed Jun 20, 2012 10:44 am

Re: MP: View matrix problem

Postby Odin_KG » Wed Jun 20, 2012 5:38 pm

hi,

Is there something I go wrong?

View matrix influences the orintation of particles and sorting of particles according to the distance of the camera. You can't move emitter changing view matrix. You should use Magic_SetEmitterPosition to move emitter.

Or magic particle will alter/reset my d3d device matrix ?

Magic Particles does not reset your matrix. Magic Particles is independent on DX or any engine.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: MP: View matrix problem

Postby NDark » Thu Jun 21, 2012 4:02 am

Odin_KG wrote:hi,


View matrix influences the orintation of particles and sorting of particles according to the distance of the camera. You can't move emitter changing view matrix. You should use Magic_SetEmitterPosition to move emitter.


Magic Particles does not reset your matrix. Magic Particles is independent on DX or any engine.


Hi Odin,

Thx for reply quickly.

I use MP_Emitter::SetPosition() to set emitter position ( Magic_SetEmitterPosition inside it ) , and render correctly.

However, my original problem is still, I want to sync view matrix between my scene and magic particle, but failed.
When I backward ( far from my scene ) 3d object is far away, but magic particle is the same distance with my camera.

I'm sure my viewmatrix is changed and set to magic library before rendering magic paricle like this:
Code: Select all
         GlueMatrix d3dwrap( MyViewMatrix ) ;
         D3DXMATRIX view = d3dwrap ;
         Magic_SetViewMatrix((MAGIC_MATRIX*)&view);

         MP.UpdateByTimer() ;
         MP.Render();

Did I miss something?


My 2nd question is about rotate of emitter.
No matter I use MP_Emitter::SetDirection() , MP_Emitter::Direct(), or MP_Emitter::Rotate() to modify the emitter, the rotate status seems strange. The MAGIC_DIRECTION is quaternion as I know, so I just set a small rotate radian along with one axis , and want it rotate by itself. However, whether it does not rotate, nor it rotates in a different way from my though( too large, or wrong axis ).
What is the difference between those 3 methods?

NDark
NDark
 
Posts: 6
Joined: Wed Jun 20, 2012 10:44 am

Re: MP: View matrix problem

Postby Odin_KG » Fri Jun 22, 2012 6:23 pm

Hi NDark,

I'm sure my viewmatrix is changed and set to magic library before rendering magic paricle like this:

GlueMatrix d3dwrap( MyViewMatrix ) ;
D3DXMATRIX view = d3dwrap ;
Magic_SetViewMatrix((MAGIC_MATRIX*)&view);

MP.UpdateByTimer() ;
MP.Render();


Did I miss something?

It seems to me your code is right.

Please, try a new version of API. I attached the file. It is possible some problems were fixed.

What is the difference between those 3 methods?

These methods are described in manual for wrapper. Argument of MP_Emitter::Rotate() is the offset. Argument of MP_Emitter::Direct() is the absolution value.
Also you should normalize the quaternions.
Attachments
magic3dwin.zip
new version
(278.78 KiB) Downloaded 3132 times
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: MP: View matrix problem

Postby NDark » Mon Jun 25, 2012 4:02 am

Odin_KG wrote:
It seems to me your code is right.

Please, try a new version of API. I attached the file. It is possible some problems were fixed.


I use your new dll/lib, it fixs the rotate problems, bravo!!

And I found I misunderstand the meaning of Magic_SetViewMatrix() , It seams defining the matrix each particle. ( But I thought it's matrix of emitter originally )

original particle from samples , see attachment : 3d_demo_Steam2_org.jpg

when i rotate the camera away from emitter , the emitter is at the same position , but the particle twists , see attachment :
3d_demo_Steam2_rotate.jpg


If there is no such matrix of whole environment of magic particle lib. , I guess I have to adjust each emitter's position whenever the camera is moving.
Attachments
3d_demo_Steam2_rotate.jpg
3d_demo_Steam2_rotate.jpg
3d_demo_Steam2_rotate.jpg (36.05 KiB) Viewed 60596 times
3d_demo_Steam2_org.jpg
3d_demo_Steam2_org.jpg
3d_demo_Steam2_org.jpg (31.13 KiB) Viewed 60588 times
NDark
 
Posts: 6
Joined: Wed Jun 20, 2012 10:44 am

Re: MP: View matrix problem

Postby Odin_KG » Mon Jun 25, 2012 12:25 pm

I use your new dll/lib, it fixs the rotate problems, bravo!!

Thanks!
And I found I misunderstand the meaning of Magic_SetViewMatrix() , It seams defining the matrix each particle. ( But I thought it's matrix of emitter originally )

The funstion Magic_SetViewMatrix() influences all loaded emitters. It is enough to call Magic_SetViewMatrix() 1 time to draw all emitters on the scene.

when i rotate the camera away from emitter , the emitter is at the same position , but the particle twists , see attachment :

Perhaps your matrix does not coincide with DX matrix or you use the other directions of axises.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: MP: View matrix problem

Postby NDark » Tue Jul 03, 2012 2:43 am

Odin_KG wrote:
when i rotate the camera away from emitter , the emitter is at the same position , but the particle twists , see attachment :

Perhaps your matrix does not coincide with DX matrix or you use the other directions of axises.


Hi Odin_KG,

I still can't find out what's going on.
No matter how I changed the view matrix of magic particle library, the particle emitter was still at the same place as I set by using position.
When I change the view matrix( camera position ), my scene moved ( of course ) , and I can make sure the particle emitter is at my 3d world by depth test ( by letting the scene before or behind those particles. )

does that possibly cause by that Magic_Particle library use left hand coordinate , and my system (dx) use right hand coordinate?

And I guess you will use view matrix to sort your particle and rotate the sprite to face camera, and if I don't set it right, the alpha blending will fail.




NDark
NDark
 
Posts: 6
Joined: Wed Jun 20, 2012 10:44 am

Re: MP: View matrix problem

Postby Odin_KG » Tue Jul 03, 2012 4:27 pm

Hi NDark,

No matter how I changed the view matrix of magic particle library, the particle emitter was still at the same place as I set by using position.

View matrix does not influence the position of emitter. View matrix influences the orientation of particles and the sorting of particles.

When I change the view matrix( camera position ), my scene moved ( of course ) , and I can make sure the particle emitter is at my 3d world by depth test ( by letting the scene before or behind those particles. )

I do not understand. Do you want to say that your scene is moved, but the particles is not moved ?

does that possibly cause by that Magic_Particle library use left hand coordinate , and my system (dx) use right hand coordinate?

Directions of axes for 3D-emitters:
x - to the right, y - upwards, z - perpendicular to the screen.

The wrapper sets view matrix using the following function:
Code: Select all
// eng: Calculation of view matrix (analogue of D3DXMatrixLookAtLH from Direct3D)
// rus: Расчет матрицы вида (аналог D3DXMatrixLookAtLH из Direct3D)
void MatrixLookAtLH(MAGIC_MATRIX* m, MP_POSITION* peye, MP_POSITION* pat, MP_POSITION* pup)
{
   MP_POSITION right, rightn, up, upn, vec, vec2;

   vec2=(*pat)-(*peye);
   
   vec=vec2;
   vec.Normalize();

   right.Cross(pup,&vec);
   up.Cross(&vec,&right);

   rightn=right;
   rightn.Normalize();

   upn=up;
   upn.Normalize();
   
   m->m[0][0] = rightn.x;
    m->m[1][0] = rightn.y;
    m->m[2][0] = rightn.z;
    m->m[3][0] = -peye->Dot(&rightn);
    m->m[0][1] = upn.x;
    m->m[1][1] = upn.y;
    m->m[2][1] = upn.z;
    m->m[3][1] = -peye->Dot(&upn);
    m->m[0][2] = vec.x;
    m->m[1][2] = vec.y;
    m->m[2][2] = vec.z;
    m->m[3][2] = -peye->Dot(&vec);
    m->m[0][3] = 0.0f;
    m->m[1][3] = 0.0f;
    m->m[2][3] = 0.0f;
    m->m[3][3] = 1.0f;
}

And I guess you will use view matrix to sort your particle and rotate the sprite to face camera, and if I don't set it right, the alpha blending will fail.

Yes, you are right.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: MP: View matrix problem

Postby NDark » Wed Jul 04, 2012 2:53 am

Odin_KG wrote:Hi NDark,

No matter how I changed the view matrix of magic particle library, the particle emitter was still at the same place as I set by using position.

View matrix does not influence the position of emitter. View matrix influences the orientation of particles and the sorting of particles.



Hi Odin_KG,

I ask the questions detail because I found the alpha blending not so well in some emitters, but fine at most emitters.
I draw a diagram to show my problem.

The upper part of diagram is initial scene : the camera is at 0 0 0 ( the view matrix send to magic particle library is shown aside), my scene is at z -200 , and I set the emitter at 0 0 +900. ( This is my 1st question: why I shall set the emitter to positive z, and that is the reason I doubt the view matrix is not coincide. ) In this case I can see the scene and particles clearly, the particles are further behind my scene ( z-test succeed )


At the lower part of diagram, I moved backward of my camera, and so were the view matrix changed. My scene moved further and smaller correctly. However, the particles still at the same distance from camera, and the same size I saw them from my camera. Finally my scene moved behind the particles.

In conclusion, as you said, the view matrix doesn't affect the position of emitters, therefore I might have to change emitters' positions when I move my camera.

My 2nd question is that the view matrix I pass to magic library is correctly or not ? If I still found some alpha blending problem ( ex. see the texture quad boundary clearly, my attachment screenshot1.jpg ) at some emitters, what might cause this?

Thx a lot,


NDark
Attachments
screenshot1.jpg
screenshot1.jpg
screenshot1.jpg (86.16 KiB) Viewed 60521 times
MagicParticleViewMatrixProblem1.png
MagicParticleViewMatrixProblem1.png
MagicParticleViewMatrixProblem1.png (31.03 KiB) Viewed 60525 times
NDark
 
Posts: 6
Joined: Wed Jun 20, 2012 10:44 am

Re: MP: View matrix problem

Postby Odin_KG » Thu Jul 05, 2012 2:02 pm

Hi NDark,

At the lower part of diagram, I moved backward of my camera, and so were the view matrix changed. My scene moved further and smaller correctly. However, the particles still at the same distance from camera, and the same size I saw them from my camera. Finally my scene moved behind the particles.

I think it is main question. API returns the coordinates of vertexes for each particle. These coordinates will be the same for both your situations. Perhaps you transform these coordinates by world matrix (it is bad idea). I think you need to create the emitter with 1 particle and test this situation more detailed. API draws nothing, you get the coordinates only.

My 2nd question is that the view matrix I pass to magic library is correctly or not ?

You may use DX wrapper to get the answer. Set camera and emitter the same your game.

screenshort1.jpg is not understood.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Next

Return to Magic Particles

Who is online

Users browsing this forum: No registered users and 3 guests

cron