Jump to content
  • Advertisement
Sign in to follow this  
TransformedBG

Meshes and Primatives

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

based on my old thread which i got to work perfectly

http://www.gamedev.net/topic/620018-one-star-instead-of-many/page__fromsearch__1

i made a second class i called asteroids

same kind of idea:

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?
};



same kind of global
//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;


same kind of create function:
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.Mesh =asteroidMesh;
asteroids.Location = asteroid_matrix;
asteroids.Mtrl = d3d::GREEN_MTRL;
asteroids.z -= asteroid_velocity;
asteroids.x = 30.0f - (rand()%60);
asteroids.y = 30.0f - (rand()%60);
}
return true;
}



same kind of render:
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.Mesh, 0);
D3DXMatrixTranslation(&asteroids.Location,asteroids.x,asteroids.y,asteroids.z);

device->SetTransform(D3DTS_WORLD, &asteroids.Location);
asteroids.Mesh->DrawSubset(0);
}
for(int i = 0; i < TOTAL_ASTEROIDS; i++) d3d::Release<ID3DXMesh*>(asteroids.Mesh);
}


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.

void moveAsteroids(IDirect3DDevice9* device, const int Height, const int Width, int dir)
{
for(int i = 0; i < TOTAL_ASTEROIDS; i++)
{
asteroids.direction = dir;
device->SetMaterial(&asteroids.Mtrl);
device->SetTransform(D3DTS_WORLD, &asteroids.Location);
D3DXCreateSphere(device,8.2f, 8, 50, &asteroids.Mesh, 0);
D3DXMatrixTranslation(&asteroids.Location,asteroids.x,asteroids.y,asteroids.z);

asteroids.Mesh->DrawSubset(0);

asteroids.z -= 0.5f;
//if turning left '4' stars move right
if(asteroids.direction == 4)
{
asteroids.x += 0.05f;
if(asteroids.x >= 30) asteroids.x = -30;
}

//if turning right '6' move left
if(asteroids.direction == 6)
{
asteroids.x -= 0.05f;
if(asteroids.x <= -30) asteroids.x = 30;
}
//if going Up '8' stars move down
if(asteroids.direction == 8)
{
asteroids.y -= 0.05f;
if(asteroids.y <= -30) asteroids.y = 30;
}
//if going up and right '8' and '6' stares move down and left
if(asteroids.direction == 9)
{
asteroids.y -= 0.05f;
asteroids.x -= 0.05f;
if(asteroids.x <= -30) asteroids.x = 30;
if(asteroids.y <= -30) asteroids.y = 30;
}
//if going up and left '8' and '4' stares move down and right
if(asteroids.direction == 7)
{
asteroids.y -= 0.05f;
asteroids.x += 0.05f;
if(asteroids.x >= 30) asteroids.x = -30;
if(asteroids.y <= -30) asteroids.y = 30;
}
//if going down and right '2' and '3' stares move up and left
if(asteroids.direction == 3)
{
asteroids.y += 0.05f;
asteroids.x -= 0.05f;
if(asteroids.x <= -30) asteroids.x = 30;
if(asteroids.y >= 30) asteroids.y = -30;
}
//if going down '2' stares move up
if(asteroids.direction == 2)
{
asteroids.y += 0.05f;
if(asteroids.y >= 30) asteroids.y = -30;
}
//if going down and left '1' and '2' stares move up and right
if(asteroids.direction == 1)
{
asteroids.y += 0.05f;
asteroids.x += 0.05f;
if(asteroids.x >= 30) asteroids.x = -30;
if(asteroids.y >= 30) asteroids.y = -30;
}


if(asteroids.z <= Near_Depth) asteroids.z = Far_Depth;
}
}


Dont know if anyone could shed some light on the idea as to why this might be happening.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!