d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ / Class / Directx > Need Some Help
Add Reply New Topic New Poll
Member
Posts: 4,065
Joined: Oct 4 2007
Gold: 4.19
Warn: 10%
Jun 9 2013 10:20am
Hi! I'm basicly new in programming, just cutting code slices over the internet.

Basicly: Now I'd like to render a cube on the shortest way. I have some problem with the following code:

void D3DManage::Cube(potential variable trans, float x, float y, float z)
{
D3DXMATRIX trans;
D3DXMatrixTranslation(&trans, x, y, z);
device->SetTransform(D3DTS_WORLD, &(trans));

for (int i = 0; i < 6; i++) {
device->DrawIndexedPrimitive(
D3DPT_TRIANGLESTRIP,
0,
0,
8,
i*4,
2);
}
}

with this method, I can draw cubes in my render function like this:

d3dManager->Cube(first, 2.0f, 1.0f, 5.0f);
d3dManager->Cube(second, 4.0f, 1.0f, 6.0f);

I need your help to find the correct variable type to do the "trans" step :)

This post was edited by lowxair on Jun 9 2013 10:21am
Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Jun 9 2013 11:00am
well you have 2 variables called "trans"

the one inside the function overwrites the trans from the parameters

edit: maybe your code works if you delete the second one.

This post was edited by Richter on Jun 9 2013 11:04am
Member
Posts: 4,065
Joined: Oct 4 2007
Gold: 4.19
Warn: 10%
Jun 9 2013 11:12am
Quote (Richter @ Jun 9 2013 05:00pm)
well you have 2 variables called "trans"

the one inside the function overwrites the trans from the parameters

edit: probably it works like this:
Code
void D3DManage::Cube(D3DXMATRIX trans, float x, float y, float z)
{
D3DXMatrixTranslation(&trans, x, y, z);
device->SetTransform(D3DTS_WORLD, &(trans));

note that i deleted the first line inside the function



yes it works once, but if I'd like to draw another cube with a variable D3DMATRIX I need a new D3DMATRIX

MAYBE a solution

1. I make a class and try to draw them this way

cube1 = new Cube (D3DMATRIX, float, float, float);

cube2 = new Cube (D3DMATRIX, float, float, float);

2. Make an array:

void D3DManage::Cube(int i, float x, float y, float z)
{
D3DMATRIX trans[i];
D3DXMatrixTranslation(&trans[i], x, y, z);
device->SetTransform(D3DTS_WORLD, &(trans[i]));

This post was edited by lowxair on Jun 9 2013 11:13am
Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Jun 9 2013 11:21am
are you sure, that "first" is a D3DXMATRIX ?

d3dManager->Cube(first, 2.0f, 1.0f, 5.0f);

we don't have enough code to tell where the problem is
...and your solutions are crappy xD
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll