TransformedBG

Members
  • Content count

    18
  • Joined

  • Last visited

Community Reputation

122 Neutral

About TransformedBG

  • Rank
    Member
  1. So far this is what i have now... I just got the light to light up the asteroids loading a texture into it.. However the texture doenst quite show.. It comes out brown instead of white... So i know there is a texture loading
  2. Never really used PIX... But i know that the texture is being set... Im looking at it and im about 99% sure its a lighting issue.. Granted it could be the fact that i have my Z cords on my asteroid set to 80? i dont know... i can change a texture to a Material color and it works fine.
  3. So programming calls go like so: [CODE] IDirect3DTexture9* my_texture; //make a texture void setupTexture() //set up the texture { //D3DXCreateTextureFromFile(Device,"ast.jpg",&my_texture); if(FAILED(D3DXCreateTextureFromFile(Device,"ast.jpg",&my_texture))) { ::MessageBox(0, "Tex - FAILED", 0, 0); } } [/CODE] Next i Create an asteroid in my message loop: [CODE] int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) { main_instance = hinstance; if(!d3d::InitD3D(hinstance, Width, Height, true, D3DDEVTYPE_HAL, &Device)) { ::MessageBox(0, "InitD3D() - FAILED", 0, 0); return 0; } if(!Setup()) { ::MessageBox(0, "Setup() - FAILED", 0, 0); return 0; } createAsteroid(Device,Height,Width, my_texture); //create asteroid d3d::EnterMsgLoop(Display); Cleanup(); Device->Release(); return 0; } [/CODE] I have a struct for an asteroid: [CODE] struct ASTEROID { LPD3DXMESH Mesh; D3DMATERIAL9 Mtrl; D3DXMATRIX Location; IDirect3DTexture9* Texture; float x; // Asteriod X Posistion float y; // Asteriod Y Posistion float z; float raduis; int hit; int direction; bool visible; // were we collide? bool split; }; [/CODE] I build a matrix of asteroids that i want to texture [CODE] bool createAsteroid(IDirect3DDevice9* device, const int Height, const int Width, IDirect3DTexture9* texture) { time_t now = time(0); srand((unsigned int )&now); for(int i = 0; i < TOTAL_ASTEROIDS + level; i++) { asteroids[i].Location = asteroid_matrix[i]; asteroids[i].Texture = texture; //<- texture set asteroids[i].z = 80; asteroids[i].x = 20.0f - (rand()%60); if(asteroids[i-1].x <= asteroids[i].x + 20) asteroids[i].x = 20.0f - (rand()%60); asteroids[i].y = 20.0f - (rand()%60); if(asteroids[i-1].y <= asteroids[i].y + 20) asteroids[i].y = 20.0f - (rand()%60); } return true; } [/CODE] next i move and render the asteroids :this is my recursive loop: [CODE] bool render(IDirect3DDevice9* device, const int Height, const int Width) { if(!device)return false; moveAsteroids(device, Height, Width); device->BeginScene(); renderAsteroids(device); device->EndScene(); return true; } [/CODE] which movement is just moving cords no big deal then re render the object: [CODE] void renderAsteroids(IDirect3DDevice9* device) { D3DLIGHT9 light; ZeroMemory(&light,sizeof(light)); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse = d3d::WHITE; light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f); device->SetLight(0,&light); device->LightEnable(0,true); light.Direction = D3DXVECTOR3(1.0f,0.3f,1.0f); device->SetLight(1,&light); device->LightEnable(1,true); //set light render states device->SetRenderState(D3DRS_NORMALIZENORMALS, true); device->SetRenderState(D3DRS_SPECULARENABLE, false); astroidNotHit(device); } [/CODE] Problem is the Texture is created (doesnt fail and prompt out) ... i can see that the value is being applied to my structure... but i can not see the asteroid on my screen.. i have a feeling the problem is my lighting. Any suggestions?
  4. Meshes and Primatives

    no one?
  5. Meshes and Primatives

    based on my old thread which i got to work perfectly [url="http://www.gamedev.net/topic/620018-one-star-instead-of-many/page__fromsearch__1"]http://www.gamedev.net/topic/620018-one-star-instead-of-many/page__fromsearch__1[/url] i made a second class i called asteroids same kind of idea: [code]struct ASTEROID { LPD3DXMESH Mesh; D3DMATERIAL9 Mtrl; LPDIRECT3DTEXTURE9* Texture; D3DXMATRIX Location; float x; // Star X Posistion float y; // Star Y Posistion float z; // Star Z Position ( = velocity) int direction; bool visible; // did we collide? };[/code] same kind of global [code]//Stars IDirect3DVertexBuffer9 * asteroid_VB; const int TOTAL_ASTEROIDS = 5; ASTEROID asteroids[TOTAL_ASTEROIDS]; LPD3DXMESH asteroidMesh; LPDIRECT3DTEXTURE9* texture; D3DXMATRIX asteroid_matrix[TOTAL_ASTEROIDS]; float asteroid_velocity = 0.2f; const int Far_Depth = 100; const int Near_Depth = 00; [/code] same kind of create function: [code]bool createAsteroid(IDirect3DDevice9* device, const int Height, const int Width) { D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH(&proj,D3DX_PI * 0.25f , (float)Width/(float)Height, 0.01f, 1000.0f); device->SetTransform(D3DTS_PROJECTION,&proj); time_t now = time(0); srand((unsigned int )&now); D3DXMATRIX V; D3DXMatrixIdentity(&V); device->SetTransform(D3DTS_WORLD,&V); device->SetTransform(D3DTS_VIEW, &V); for(int i = 0; i < TOTAL_ASTEROIDS; i++) { asteroids[i].Mesh =asteroidMesh; asteroids[i].Location = asteroid_matrix[i]; asteroids[i].Mtrl = d3d::GREEN_MTRL; asteroids[i].z -= asteroid_velocity; asteroids[i].x = 30.0f - (rand()%60); asteroids[i].y = 30.0f - (rand()%60); } return true; }[/code] same kind of render: [code]void renderAsteroids(IDirect3DDevice9* device) { device->SetRenderState(D3DRS_LIGHTING,FALSE); device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); device->SetTextureStageState(0, D3DTSS_COLORARG1,D3DTA_DIFFUSE); for(int i = 0; i < TOTAL_ASTEROIDS; i++) { D3DXCreateSphere(device, 8.2f, 8, 50, &asteroids[i].Mesh, 0); D3DXMatrixTranslation(&asteroids[i].Location,asteroids[i].x,asteroids[i].y,asteroids[i].z); device->SetTransform(D3DTS_WORLD, &asteroids[i].Location); asteroids[i].Mesh->DrawSubset(0); } for(int i = 0; i < TOTAL_ASTEROIDS; i++) d3d::Release<ID3DXMesh*>(asteroids[i].Mesh); }[/code] problem im having is when they render and move they take my premitive stars and put them Way behind them and move them around the screen as they move. the stars do not stay on the screen like i was hoping. [code]void moveAsteroids(IDirect3DDevice9* device, const int Height, const int Width, int dir) { for(int i = 0; i < TOTAL_ASTEROIDS; i++) { asteroids[i].direction = dir; device->SetMaterial(&asteroids[i].Mtrl); device->SetTransform(D3DTS_WORLD, &asteroids[i].Location); D3DXCreateSphere(device,8.2f, 8, 50, &asteroids[i].Mesh, 0); D3DXMatrixTranslation(&asteroids[i].Location,asteroids[i].x,asteroids[i].y,asteroids[i].z); asteroids[i].Mesh->DrawSubset(0); asteroids[i].z -= 0.5f; //if turning left '4' stars move right if(asteroids[i].direction == 4) { asteroids[i].x += 0.05f; if(asteroids[i].x >= 30) asteroids[i].x = -30; } //if turning right '6' move left if(asteroids[i].direction == 6) { asteroids[i].x -= 0.05f; if(asteroids[i].x <= -30) asteroids[i].x = 30; } //if going Up '8' stars move down if(asteroids[i].direction == 8) { asteroids[i].y -= 0.05f; if(asteroids[i].y <= -30) asteroids[i].y = 30; } //if going up and right '8' and '6' stares move down and left if(asteroids[i].direction == 9) { asteroids[i].y -= 0.05f; asteroids[i].x -= 0.05f; if(asteroids[i].x <= -30) asteroids[i].x = 30; if(asteroids[i].y <= -30) asteroids[i].y = 30; } //if going up and left '8' and '4' stares move down and right if(asteroids[i].direction == 7) { asteroids[i].y -= 0.05f; asteroids[i].x += 0.05f; if(asteroids[i].x >= 30) asteroids[i].x = -30; if(asteroids[i].y <= -30) asteroids[i].y = 30; } //if going down and right '2' and '3' stares move up and left if(asteroids[i].direction == 3) { asteroids[i].y += 0.05f; asteroids[i].x -= 0.05f; if(asteroids[i].x <= -30) asteroids[i].x = 30; if(asteroids[i].y >= 30) asteroids[i].y = -30; } //if going down '2' stares move up if(asteroids[i].direction == 2) { asteroids[i].y += 0.05f; if(asteroids[i].y >= 30) asteroids[i].y = -30; } //if going down and left '1' and '2' stares move up and right if(asteroids[i].direction == 1) { asteroids[i].y += 0.05f; asteroids[i].x += 0.05f; if(asteroids[i].x >= 30) asteroids[i].x = -30; if(asteroids[i].y >= 30) asteroids[i].y = -30; } if(asteroids[i].z <= Near_Depth) asteroids[i].z = Far_Depth; } }[/code] Dont know if anyone could shed some light on the idea as to why this might be happening.
  6. Trying to make a room... Need some help

    [quote name='lomateron' timestamp='1328497768' post='4910025'] maybe the way your index buffers tell to draw the cube is in a way that they can only be seen when you are outside the cube, not from inside [/quote] thats what happened.. then i was way to close to see it lol
  7. one star instead of many...

    You sir are my hero!
  8. Im just trying to make the old flying through space screen saver in direct X and could use a little help. oh the star is just a basic struct: [code]struct STAR { float x; // Star X Posistion float y; // Star Y Posistion float z; // Star Z Position float velocity; // Star Velocity int direction; DWORD color; // Star Color bool hyperspace; //boost? }; [/code] global variables [code]//Stars IDirect3DVertexBuffer9 * star_VB; const int TOTAL_STARS = 250; STAR stars[TOTAL_STARS]; //star vertex float star_velocity = 0.1f; const int Far_Depth = 100; const int Near_Depth = 20;[/code] //how i create my star[code]bool createStars(IDirect3DDevice9* device, const int Height, const int Width) { D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH(&proj,D3DX_PI * 0.25f , (float)Width/(float)Height, 0.01f, 1000.0f);//45, 1.0f, 0.1f, 500.0f)); device->SetTransform(D3DTS_PROJECTION,&proj); time_t now = time(0); srand((unsigned int )&now); D3DXMATRIX V; D3DXMatrixIdentity(&V); device->SetTransform(D3DTS_WORLD,&V); device->SetTransform(D3DTS_VIEW, &V); for(int i=0; i < TOTAL_STARS;i++) { stars[i].z -= star_velocity; stars[i].x = 30.0f - (rand()%60); stars[i].y = 30.0f - (rand()%60); stars[i].z = Near_Depth + (float)(rand()%(Far_Depth - Near_Depth)); stars[i].color = d3d::WHITE; } return true; }[/code] which i call in my winMain: [code]// WinMain int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) { main_instance = hinstance; if(!d3d::InitD3D(hinstance, Width, Height, true, D3DDEVTYPE_HAL, &Device)) { ::MessageBox(0, "InitD3D() - FAILED", 0, 0); return 0; } if(!Setup()) { ::MessageBox(0, "Setup() - FAILED", 0, 0); return 0; } bool test = true; test = createStars(Device,Height,Width); if(test == false) { ::MessageBox(0, "createStars() - FAILED",0,0); return 0; } d3d::EnterMsgLoop(Display); Cleanup(); Device->Release(); return 0; }[/code] and i call the function render() in my display [code]bool render(IDirect3DDevice9* device) { if(!device)return false; moveStars(device); device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, d3d::BLACK, 1.0f,0); device->BeginScene(); renderStars(device); device->EndScene(); return true; }[/code] which calls movestars: [code]void moveStars(IDirect3DDevice9* device) { for(int i = 0; i < TOTAL_STARS; i++) { //move the star stars[i].z -= star_velocity; if(stars[i].z <= Near_Depth) stars[i].z = Far_Depth; if(stars[i].direction == 2) { stars[i].x += 0.1f; } } }[/code] then renders them: [code]void renderStars(IDirect3DDevice9* device) { device->SetRenderState(D3DRS_LIGHTING,FALSE); device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); device->SetTextureStageState(0, D3DTSS_COLORARG1,D3DTA_DIFFUSE); device->CreateVertexBuffer(TOTAL_STARS*sizeof(stars),D3DUSAGE_WRITEONLY, CUSTOMFVF,D3DPOOL_MANAGED,&star_VB,NULL); VOID* temp_pointer_vb; star_VB->Lock(0,TOTAL_STARS*sizeof(stars),&temp_pointer_vb,0); memcpy(temp_pointer_vb,stars,TOTAL_STARS); star_VB->Unlock(); device->SetStreamSource(0,star_VB,0,sizeof(stars)); device->SetFVF(CUSTOMFVF); device->DrawPrimitive(D3DPT_POINTLIST,0,TOTAL_STARS); star_VB->Release(); }[/code] Now problem im having is im only rendering 1 star somewhere on the screen over and over again... so the move function is obviously working... Problem is that it should be rendering 250 stars.. Just wondering if someone might have some thoughts on this..
  9. Trying to make a room... Need some help

    NM i figured it out...
  10. Okay so I have been trying to build a basic room with textures right now im just trying to figure out how to texture a cube and be able to move throughout space. unfortunately my cube isn't showing up and i'm not sure why... hoping maybe someone can shed some light on this: main.cpp: [code]#include "base.h" #include "camera.h" #include "room.h" // Globals IDirect3DDevice9* Device = 0; float intiTime = (float)timeGetTime(); LPDIRECT3DTEXTURE9 texture; D3DXMATRIX World; IDirect3DVertexBuffer9* Floor = 0; // vertex buffer to store IDirect3DIndexBuffer9* floorBuff = 0; //set screen const int Width = 900; const int Height = 600; //Position tracking Camera TheCamera; float camPosX = 0.0f,camPosY = 0.0f, camPosZ = -5.0f; bool drawFloor() { D3DXCreateTextureFromFile(Device, // the Direct3D device "carpet.jpg", // the filename of the texture &texture); // the address of the texture storage if(!texture) { ::MessageBox(0, "D3DXCreateTextureFromFile() - FAILED", 0, 0); return false; } CUSTOMVERTEX vertices[] = { { -3.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, }, // side 1 { 3.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, }, { -3.0f, 3.0f, 3.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, }, { 3.0f, 3.0f, 3.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, }, { -3.0f, -3.0f, -3.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, }, // side 2 { -3.0f, 3.0f, -3.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, }, { 3.0f, -3.0f, -3.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, }, { 3.0f, 3.0f, -3.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, }, { -3.0f, 3.0f, -3.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, }, // side 3 { -3.0f, 3.0f, 3.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, }, { 3.0f, 3.0f, -3.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, }, { 3.0f, 3.0f, 3.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, }, { -3.0f, -3.0f, -3.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, }, // side 4 { 3.0f, -3.0f, -3.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, }, { -3.0f, -3.0f, 3.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, }, { 3.0f, -3.0f, 3.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, }, { 3.0f, -3.0f, -3.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, }, // side 5 { 3.0f, 3.0f, -3.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, }, { 3.0f, -3.0f, 3.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }, { 3.0f, 3.0f, 3.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, }, { -3.0f, -3.0f, -3.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, }, // side 6 { -3.0f, -3.0f, 3.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }, { -3.0f, 3.0f, -3.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, }, { -3.0f, 3.0f, 3.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, }, }; Device->CreateVertexBuffer(24*sizeof(CUSTOMVERTEX),0,CUSTOMFVF,D3DPOOL_MANAGED,&Floor,NULL); VOID* pVoid; //void pointer Floor->Lock(0,0,(void**)&pVoid,0); memcpy(pVoid,vertices,sizeof(vertices)); Floor->Unlock(); // create the indices using an int array short indices[] = { 0, 1, 2, // side 1 2, 1, 3, 4, 5, 6, // side 2 6, 5, 7, 8, 9, 10, // side 3 10, 9, 11, 12, 13, 14, // side 4 14, 13, 15, 16, 17, 18, // side 5 18, 17, 19, 20, 21, 22, // side 6 22, 21, 23, }; Device->CreateIndexBuffer(36*sizeof(short),0,D3DFMT_INDEX16,D3DPOOL_MANAGED,&floorBuff,NULL); floorBuff->Lock(0,0,(void**)&pVoid,0); memcpy(pVoid,indices,sizeof(indices)); floorBuff->Unlock(); return true; } //Lighting to see currObject void renderLight() { //Set up Directional Light D3DXVECTOR3 dir(1.0f, -0.0f, 0.25f); D3DXCOLOR c = d3d::WHITE; D3DLIGHT9 dirLight = d3d::InitDirectionalLight(&dir, &c); //enable lights Device->SetLight(0, &dirLight); // 0,1,2,3 etc for whatever light your on. / name of light Device->LightEnable(0, true); //set light render states Device->SetRenderState(D3DRS_NORMALIZENORMALS, true); Device->SetRenderState(D3DRS_SPECULARENABLE, false); } // Framework functions bool Setup() { renderLight(); // Set camera. D3DXVECTOR3 pos(camPosX, camPosY, camPosZ); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMATRIX V; D3DXMatrixLookAtLH(&V, &pos, &target, &up); Device->SetTransform(D3DTS_VIEW, &V); // Set projection matrix. D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI * 0.25f, // 45 - degree (float)Width / (float)Height, 0.01f, 1000.0f); Device->SetTransform(D3DTS_PROJECTION, &proj); return true; } void Cleanup() { d3d::Release<IDirect3DVertexBuffer9*>(Floor); d3d::Release<IDirect3DIndexBuffer9*>(floorBuff); //d3d::Release<ID3DXMesh*>; } //render the world void render(float timeDelta) { // Render Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); Device->BeginScene(); //INSERT WHAT TO BE RENDERED drawFloor(); Device->SetStreamSource(0,Floor,0,sizeof(CUSTOMVERTEX)); Device->SetIndices(floorBuff); Device->SetFVF(CUSTOMFVF); Device->SetTexture(0,texture); Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,24,0,12); Device->EndScene(); } //uptates current state bool Display(float timeDelta) { if( Device ) { if( ::GetAsyncKeyState('W') & 0x8000f ) TheCamera.walk(4.0f * timeDelta); if( ::GetAsyncKeyState('S') & 0x8000f ) TheCamera.walk(-4.0f * timeDelta); if( ::GetAsyncKeyState('A') & 0x8000f ) TheCamera.strafe(-4.0f * timeDelta); if( ::GetAsyncKeyState('D') & 0x8000f ) TheCamera.strafe(4.0f * timeDelta); if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f ) TheCamera.pitch(0.3f * timeDelta); if( ::GetAsyncKeyState(VK_UP) & 0x8000f ) TheCamera.pitch(-.3f * timeDelta); if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f ) TheCamera.yaw(-0.3f * timeDelta); if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f ) TheCamera.yaw(0.3f * timeDelta); // Update the view matrix representing the cameras // new position/orientation. D3DXMATRIX V; TheCamera.getViewMatrix(&V); Device->SetTransform(D3DTS_VIEW, &V); render(timeDelta); Device->Present(0, 0, 0, 0); } return true; } // WndProc LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch( msg ) { case WM_DESTROY: ::PostQuitMessage(0); break; case WM_KEYDOWN: if( wParam == VK_ESCAPE ) ::DestroyWindow(hwnd); break; break; } return ::DefWindowProc(hwnd, msg, wParam, lParam); } // WinMain int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevInstance, PSTR cmdLine,int showCmd) { if(!d3d::InitD3D(hinstance, Width, Height, true, D3DDEVTYPE_HAL, &Device)) { ::MessageBox(0, "InitD3D() - FAILED", 0, 0); return 0; } if(!Setup()) { ::MessageBox(0, "Setup() - FAILED", 0, 0); return 0; } d3d::EnterMsgLoop( Display ); Cleanup(); Device->Release(); return 0; } [/code] attached is a zip with all files to run it.. but im just having one of those moments i could use some more eyes.
  11. Drawing subset of an array of pointers

    Never mind loop in a loop lol durp.. figured it out
  12. Short version lets say i want to make 10 objects: Atom, Bullet, Tree, etc, etc. using ID3DXMesh's. My idea was it would be something like: [CODE] //setup objects in world ID3DXMesh** Objects[10] = {0,0,0,0,0,0,0,0,0}; ID3DXMesh *Atom[4] = {0,0,0,0}; [/CODE] [CODE] //set up 4 meshes for atom void renderAtom() { D3DXCreateTorus(Device, 0.1f, 2.0f, 20, 20, &Atom[0], 0); D3DXCreateSphere(Device, 0.5f, 20, 20, &Atom[1], 0); D3DXCreateTorus(Device, 0.1f, 2.0f, 20, 20, &Atom[2], 0); D3DXCreateTorus(Device, 0.1f, 2.0f, 20, 20, &Atom[3], 0); } [/CODE] [CODE] //set atom to the first pointer Objects[0] = Atom; [/CODE] do the rest of the objects [CODE] //render the world void render(float timeDelta) { // Render Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); Device->BeginScene(); for(int i = 0; i < 10; i++) { Device->SetMaterial(&Mtrls[i]); Device->SetTransform(D3DTS_WORLD, &Worlds[i]); Objects[i]->DrawSubset(0); } Device->EndScene(); } [/CODE] problem is DrawSubset needs to point to a class/struct/union or generic type. Would there be an easy way to do this?
  13. How to arc an object across the screen?

    [quote name='iedoc' timestamp='1321631890' post='4885338'] So your camera is not moving I assume, since your able to compare a world coordinate with a screen coordinate. Otherwise, if you want the sun to move relative to the camera, you will just have to do that transformation (translation then rotation) first, and then do another translation to the position of your camera. but doing this will have the sun always revolve around the camera instead of the world, which at first i thought would be weird, but I gave it a second thought and thats actually a good idea to do that, so that the sun never gets any closer to the camera, since it would look pretty unrealistic if the sun actually got closer to you while you walked towards it. So, better than worrying about the screen space, like pixels and all that, It would be better to check if its inside or outside the "frustum", which is basically a cone shaped box of everything the camera can see. This shouldn't be terribly difficult, since you should already have the field of view angle, and after the sun has rotated that field of view angle, it should be out of sight (Or nearly out of sight, you'll probably have to play with the angle values a bit to get exactly what you want), and then you could stop rotating it. I thought about it again, and to get an arc shape across the screen, it might be helpful to do two sets of transformations, the one I mentioned being SECOND. the first transformation would be a translation of a certain distance, and the rotation being the one that will give the sun an appearance of an arc across the screen (both depending on the arc you are looking for), then do the second transformation like i mentioned above [/quote] alright ill try to give that a go and see what happens.. fairly new to all this so Iv been learning as i go...
  14. How to arc an object across the screen?

    [quote name='iedoc' timestamp='1321608619' post='4885259'] It sounds like you just want the sun to rotate around the center of your world? This is very easy. All you have to do is first translate (move) the sun to the distance you want from the center of the world. Then you do a rotation, which will rotate the sun around the point (0,0,0) in world space. You would just update the angle of rotation every frame (you might want to use a timer to keep a smooth animation), and stop updating the angle after the sun gets outside the screen. I think this is what your asking right? [/quote] Yeah that's pretty much what I am asking... problem I am having is figuring out measurements... I know my (0,0,0) cord would be (.5*width, .5*height, Zvar), how do you go from [color=#000088]const[/color][color=#000000] [/color][color=#000088]int[/color][color=#000000] [/color][color=#660066]Width[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] [/color][color=#666600]([/color][color=#660066]GetSystemMetrics[/color][color=#666600]([/color][color=#000000]SM_CXSCREEN[/color][color=#666600]))[/color][color=#000000] [/color][color=#666600]-[/color][color=#000000] [/color][color=#006666]10[/color][color=#666600];[/color][color=#000000] [/color][color=#000088]const[/color][color=#000000] [/color][color=#000088]int[/color][color=#000000] [/color][color=#660066]Height[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] [/color][color=#666600]([/color][color=#660066]GetSystemMetrics[/color][color=#666600]([/color][color=#000000]SM_CYSCREEN[/color][color=#666600]))[/color][color=#000000] [/color][color=#666600]-[/color][color=#000000] [/color][color=#006666]50[/color][color=#666600];[/color] to figure out where the edges are?
  15. So I have been building a "world" out of triangle, Layering objects upon one another and learning a little bit about how to do things. Basically what i am trying to do is build a sun that will arch 180 degrees across any given size screen and stop just outside of view. I have got the sun drawn and moving however i cant get my arc right. I know this has something to do with geometry but i havent figured it out yet.. (Last time i took it was 1998 lol) so far what i have is: [code]//screen variables const int Width = (GetSystemMetrics(SM_CXSCREEN)) - 10; const int Height = (GetSystemMetrics(SM_CYSCREEN)) - 50; //Build device pointer IDirect3DDevice9* Device = 0; IDirect3DVertexBuffer9* Triangle = 0; // vertex buffer to store //Build a matrix to transform w/object D3DXMATRIX World, sunRotation; double sunXYcord = 0.0f; float sunX = -4.5f, sunY = 0.0f; // start point for x int choice = 0; //colors int r,g,b; int roofR,roofG,roofB; //sky int skyR = 51, skyG =189 ,skyB = 255; float rShift = 0.0f, gShift = 0.0f, bShift = 0.0f; struct colorVertex { colorVertex(){} colorVertex(float x, float y, float z, D3DCOLOR c) { _x = x; _y = y; _z = z, _color = c; } float _x, _y, _z; D3DCOLOR _color; static const DWORD FVF; }; const DWORD colorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE; void fillVertices(int vertCord,float x, float y, float z, int r, int g, int b) { colorVertex* vertices; Triangle->Lock(0, 0, (void**)&vertices, 0); vertices[vertCord] = colorVertex(x, y, z, D3DCOLOR_XRGB(r,g,b)); vertices[vertCord] = colorVertex(x, y, z, D3DCOLOR_XRGB(r,g,b)); vertices[vertCord] = colorVertex(x, y, z, D3DCOLOR_XRGB(r,g,b)); Triangle->Unlock(); } bool Setup() { // Create the vertex buffer. Device->CreateVertexBuffer( 3 * sizeof(colorVertex), // size in bytes D3DUSAGE_WRITEONLY, // flags colorVertex::FVF, // vertex format D3DPOOL_MANAGED, // managed memory pool &Triangle, // return create vertex buffer 0); // not used - set to 0 // Set the projection matrix. D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH( &proj, // result D3DX_PI * 0.5f, // 90 - degrees (float)Width / (float)Height, // aspect ratio 1.0f, // near plane 1000.0f); // far plane Device->SetTransform(D3DTS_PROJECTION, &proj); // Set wireframe mode render state. Device->SetRenderState(D3DRS_LIGHTING, false); //allows us to see object return true; } void drawSun(float x, float y) { r=255,g=255,b=0; //red+green = yellow //make 1 triangle top //red fillVertices(0, -0.5f, -0.5f, 1.0f,r,g,b); fillVertices(1, 0.0f, 0.5f, 1.0f,r,g,b); fillVertices(2, 0.5f, -0.5f, 1.0f,r,g,b); D3DXMatrixTranslation(&World, x, y, 2.0f); //triangle, x,y, camara view(z) Device->SetTransform(D3DTS_WORLD, &World); //transform Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT); //GOURAUD Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); //make 2 triangle bottom // yellow fillVertices(0, 0.0f, -0.5f, 1.0f,r,g,b); fillVertices(1, -0.5f, 0.5f, 1.0f,r,g,b); fillVertices(2, 0.5f, 0.5f, 1.0f,r,g,b); D3DXMatrixTranslation(&World, x, y-0.3f, 2.0f); //triangle, x,y, camara view(z) Device->SetTransform(D3DTS_WORLD, &World); Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT); Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); } void moveObjectLeft(float x, float y) { D3DXMatrixRotationX(&sunRotation, D3DXToRadian(x)); D3DXMatrixRotationY(&sunRotation, D3DXToRadian(y)); Device->SetTransform(D3DTS_WORLD,&sunRotation); } void moveObjectRight(float x, float y) { D3DXMatrixRotationX(&sunRotation, D3DXToRadian(sunX)); D3DXMatrixRotationY(&sunRotation, D3DXToRadian(sunY)); Device->SetTransform(D3DTS_WORLD,&sunRotation); } void Cleanup() { d3d::Release<IDirect3DVertexBuffer9*>(Triangle); } void render(float timeDelta) { Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0); //clear screen Device->BeginScene(); { drawGrass(); drawSky(); drawHouse(); } Device->EndScene(); Device->BeginScene(); Device->SetStreamSource(0, Triangle, 0, sizeof(colorVertex)); Device->SetFVF(colorVertex::FVF); drawSun(sunX, sunY); Device->EndScene(); } bool Display(float timeDelta) { if( Device ) { render(timeDelta); Device->Present(0, 0, 0, 0); } return true; } LRESULT CALLBACK d3d::WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch( msg ) { case WM_DESTROY: ::PostQuitMessage(0); break; case WM_KEYDOWN: if( wParam == VK_ESCAPE ) ::DestroyWindow(hwnd); if(wParam == VK_RIGHT) { sunXYcord += 4.5; if(sunXYcord < Width/2) //if circle != 90 do stuff else stop { sunX += 0.03f; sunY += 0.02f; moveObjectLeft(sunX,sunY); } if(sunXYcord > Width/2-1) { sunX += 0.03f; sunY -= 0.02f; moveObjectLeft(sunX,sunY); } } if(wParam == VK_LEFT) { sunXYcord -= 4.5; if(sunXYcord < Width/2) //if circle != 90 do stuff else stop { sunX -= 0.03f; sunY -= 0.02f; moveObjectLeft(sunX,sunY); } if(sunXYcord > Width/2-1) { sunX -= 0.03f; sunY += 0.02f; moveObjectLeft(sunX,sunY); } } /*if(wParam == VK_0x047) //G { choice = 1; } if(wParam == VK_0x048) //F { choice = 0; }*/ break; } return ::DefWindowProc(hwnd, msg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE prevInstance, PSTR cmdLine,int showCmd) { if(!d3d::InitD3D(hinstance, Width, Height, true, D3DDEVTYPE_HAL, &Device)) { ::MessageBox(0, "InitD3D() - FAILED", 0, 0); return 0; } if(!Setup()) { ::MessageBox(0, "Setup() - FAILED", 0, 0); return 0; } d3d::EnterMsgLoop( Display ); Cleanup(); Device->Release(); return 0; } [/code] Just wondering if maybe someone out there could help me out a little and see what they could come up with.