• Content count

  • Joined

  • Last visited

Community Reputation

106 Neutral

About adi0149

  • Rank
  1. Wow... that's a lot of words i don't understand... like:   Anyway... i did solve my problem (in a very  unprofessional way, i'm sure of that). You can check out a video of how it looks like here.   So... what i did was to choose a visible dimension on screen (as a ratio of the viewport's height or width) and compute the size of the object at each frame, so that it appears to have that dimension that i chose. here's the code:   // choose the size of the object with respect to vieport's width float mysize = 0.05*viewport.Width; // now find the point on the screen that is offseted with half the chosen size screenPoint.x = screenPoint.x - mysize/2; screenPoint.y = projectPoint.y - mysize/2; screenPoint.z = projectPoint.z; // now transform the screen position into a world position D3DXVec3Unproject( &worldPoint, &screenPoint, &viewport, &matProjection, &matView, &matObjectWorld ); // coorect size with rotation float boxSize = 2.0f; // assign some default size for the object, in case something goes wrong if (cos(angley) == 0) // make sure i don't devide by zero { boxSize = abs(transY - worldPoint.y); } else { boxSize = abs(transX - worldPoint.x) / abs(cos(angley)) ; }   and finally...  D3DXCreateBox(_device,boxSize,boxSize,boxSize,&_SomeBox,NULL);   Now.. what you've seen in the video was accomplished by drawing 3  cylinders with different  colors  and one cube in the middle. If anyone desires, i could put up my entire function here to have a clearer idea.   Thanks all for the advice. Any further comments would be appreciated.
  2. Thanks for the reply!   I  applied  your changes as follows:   ... everything is unchanged up to the point where i found transX, transY, transZ. Now it follows:   // #1: Set D3DTS_VIEW back to identity. D3DXMATRIX matView2; D3DXMatrixIdentity (&matView2); // #2: Create an orthographic projection matrix. D3DXMATRIX P; D3DXMatrixOrthoLH( &P, viewport.Width/20, viewport.Height/20, 1.0f, 100.0f ); _device->SetTransform(D3DTS_PROJECTION, &P); // #3: Set the scale of the cube to x = (1.0f / ScreenWidth), y = (1.0f / ScreenHeight). D3DXMATRIX mScale; D3DXMatrixIdentity(&mScale); D3DXMatrixScaling( &mScale, (1.0f / viewport.Width), (1.0f / viewport.Height), 1 ); D3DXMatrixMultiply( &matObjectWorld, &matObjectWorld, &mScale ); // #4: Set the rotation of the cube to equal that of the rotation of the world-view matrix that you used to render the first time (copy the 3×3 part of the world-view matrix). for (int i=1; i<4; i++) { for (int j=1; j<4; j++) { matView2.m[i][j] = matView.m[i][j]; } } _device->SetTransform(D3DTS_VIEW, &matView); // ... i create the cube here ... // #5: Position the cube in the lower-left of the screen (screen coordinates). D3DXMatrixTranslation(&matObjectWorld, transX, transY, transZ); _device->SetTransform(D3DTS_WORLD, &matObjectWorld);   If i do this, it works but all the scene is rendered in an orthographic projection and i lose perspective of things. So i decided to add  _device->SetTransform(D3DTS_PROJECTION, &matProjection);   just after i render the cube so everything else is kept in the initial perspective projection (i draw the cube just at the end of the scene, so everything is in perspective and just the cube is in ortho). However, if i do this, then the cube changes position when zooming, appearing to go towards the origin along Z axis when zooming in and  vice-versa  when zooming out.   So.. the thing is i would like to keep my perspective projection on all things (maybe except the cube, which looks better when is in ortho), but this doesn't work as supposed to. If you'd like, i can put up a new video to express the symptoms better.   Thanks again for the reply!
  3. Hi! I'd like to start off saying i don't have any programming training and very few knowledge, but i have messed around with several programming languages, designing tools to aid my everyday job (so i am a total amateur).   This time i'm working on something harder - it's a direct3d - mfc software and i am having lots of problems with it, since directx seems a bit hard.   Anyways... I have a direct3d environment in a mfc window and i would like to draw the coordinate system axes in the corner of the screen, as any 3d software has. I thought this would be no problem, since i found this topic, and that worked great but problems  occurred  when i started moving the camera around. I need the object to appear to be in the same spot, no matter how i pan, zoom or rotate the world (actually, i do these operations on the view matrix).   But it seems that i'm doing something wrong, and i was hoping someone could point me on the right direction, since the object i'm drawing is not scaled accordingly when i zoom, but it works perfect when panning or rotating.   I have also put up a youtube video to show you the symptoms.   This is my code for drawing the object:   void CDEMView::DrawSomeBox() { // Define the needed matrices - object world, view and project D3DXMATRIX matObjectWorld; D3DXMatrixIdentity (&matObjectWorld); // object world matrix D3DXMATRIX matView; D3DXMatrixIdentity (&matView); // view matrix D3DXMATRIX matProjection; D3DXMatrixIdentity (&matProjection); // projection matrix // Get the needed matrices _device->GetTransform(D3DTS_VIEW, &matView); _device->GetTransform(D3DTS_PROJECTION, &matProjection); // Get the viewport D3DVIEWPORT9 viewport; _device->GetViewport(&viewport); // Get the center point of the object D3DXVECTOR3* p_centerPoint = BoxCenterVector; // this is from an external variable // Get the point on the creen that is the screen projection of the object D3DXVECTOR3 projectPoint; D3DXVec3Project(&projectPoint, p_centerPoint ,&viewport, &matProjection, &matView, &matObjectWorld); // choose the screen point where the object is to be drawn, relative to the Viewport's dimensions D3DXVECTOR3 screenPoint; screenPoint.x = 0.1*viewport.Width; // x position (horizontal) is 10% of the width of the screen (0% is left, 100% is right) screenPoint.y = 0.9*viewport.Height; // y position (vertical) is 90% of the height of the screen (0% is top, 100% is bottom) screenPoint.z = projectPoint.z; // 1-projectPoint.z*60/(-zoom); //transform the screen position to a world position D3DXVECTOR3 worldPoint; D3DXVec3Unproject( &worldPoint, &screenPoint, &viewport, &matProjection, &matView, &matObjectWorld ); // now define how much to translate the box in order to get it to the point we want it to be (WorldPoint) float transX, transY, transZ; transX = worldPoint.x; transY = worldPoint.y; transZ = worldPoint.z; // define a mesh to store the object into and create the object ID3DXMesh* _SomeBox; float boxSize = 2.0f; D3DXCreateBox(_device,boxSize,boxSize,boxSize,&_SomeBox,NULL); // define a material and set its color D3DMATERIAL9 mat; // Set the RGBA for diffuse reflection. mat.Diffuse.r = 255; mat.Diffuse.g = 0; mat.Diffuse.b = 0; mat.Diffuse.a = 0.5; _device->SetMaterial(&mat); _device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); // D3DFILL_SOLID // apply the translation matrix D3DXMatrixTranslation(&matObjectWorld, transX, transY, transZ); _device->SetTransform(D3DTS_WORLD, &matObjectWorld); // draw the object _SomeBox->DrawSubset(0); // release the mesh _SomeBox->Release(); // some debugging variables debug1 = transX; debug2 = transY; debug3 = transZ; debug4 = boxSize; //debug5 = scaleFactor; manole = 0; }   Any help would be greatly appreciated. Thanks!   Edit: made a small change to the code to reflect my software.
  4. thx for help. i'll be putting your advice in action in a few minutes. i'll get back to you if it worked or not. ...and yes, vPartProp is a vector of type ParticleProperties, having stored some data about some particles :) EDIT: Finally... it works. Thank you very much! I've been trying to figure this out for a few hours now... Thx :)
  5. I know there's already been a discussion about this topic but i'm very new to programming and i couldn't make much of it. Anyway... i'm trying to write some data into a file and then read it and use it later. Here's the code: (omg... don't know how to format it) struct ParticleProperties { int shape; float red, green, blue; float dimensions[3]; float position[3]; float orientation[3]; float velocity[3]; float acceleration[3]; float forcedir[3]; float forcemag; int density; }; and: ParticleProperties read,write,load; FILE *_file,*stream,*output; vector<ParticleProperties> LoadedFromFile; fopen_s( &stream, "D:\\Scoala\\Licenta\\Back-up\\2009.09.14.ReadFiles\\Direct3D9MFC\\Direct3D9MFC\\saves\\test1.bin", "wb+" ); for (vector<ParticleProperties>::iterator write=vPartProp.begin(); write!=vPartProp.end(); write++) { fwrite(&write,sizeof(ParticleProperties),1,stream); } fclose( stream ); fopen_s( &_file,"D:\\Scoala\\Licenta\\Back-up\\2009.09.14.ReadFiles\\Direct3D9MFC\\Direct3D9MFC\\saves\\test1.bin","rb+" ); fseek (_file, 0, SEEK_END); long int size = ftell(_file); rewind(_file); long int pos = ftell(_file); while (pos < size) { fread(&read,sizeof(float),sizeof(ParticleProperties)/sizeof(float),_file); LoadedFromFile.push_back(read); pos = ftell(_file); } fclose( _file ); fopen_s( &output, "D:\\Scoala\\Licenta\\Back-up\\2009.09.14.ReadFiles\\Direct3D9MFC\\Direct3D9MFC\\saves\\test2.bin", "w+t" ); for (vector<ParticleProperties>::iterator load=LoadedFromFile.begin(); load!=LoadedFromFile.end(); load++) { fprintf( output, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d\n",load->shape, load->red, load->green, load->blue, load->dimensions[0],load->dimensions[1],load->dimensions[2],load->position[0],load->position[1],load->position[2], load->orientation[0],load->orientation[1],load->orientation[2],load->velocity[0],load->velocity[1],load->velocity[2], load->acceleration[0],load->acceleration[1],load->acceleration[2],load->forcedir[0],load->forcedir[1],load->forcedir[2], load->forcemag,load->density); } fclose( output ); I'm using the "output" to write the data in text format to actually see what i read. anyway, it seems that "write" has the correct values while writing them, but once it gets out of the "for" loop, it seems to take arbitrary values. (i don't really know if that is an issue or not since the data had already been written to the file). however, the "read" has complitely strange values (most of them zero) that have nothing to do with what i wanted to write and then read. I would like someone to give some advice on how to make this work, but do it clearly please, cause i'm n00b. :)
  6. well, i managed to fix that using CutieVertBuff->Lock(0, 0, (VOID**)&vertices, 0); but the program crashes later on, when initiating the ageia physix cooking, but i guess you wouldn't know to much about that, would you? so... since it crashes, i don't really know if that function really fixed the problem. Anyway, in case someone does know, here's my problem: i get "Unhandled exception at 0x0049f788 in Direct3D9MFC.exe: 0xC0000005: Access violation reading location 0x00000000." when calling NxInitCooking();. the gCooking seems to be uninitialized. it's value is 0x00000000. any idea why? NxCookingInterface *gCooking = NxGetCookingLib(NX_SDK_VERSION_NUMBER); gCooking->NxInitCooking();
  7. Hi! i'm very new to programming (of any kind) and i have stumbled across this error. I need to get a LPDIRECT3DVERTEXBUFFER9 and store it in a float type pointer. Any ideas on how to do that? here's how things look like: LPDIRECT3DVERTEXBUFFER9 CutieVertBuff = NULL; cutie->GetVertexBuffer(&CutieVertBuff); float* vertices = CutieVertBuff; where "cutie" is the mesh. Thanks in advance.