• Create Account

# EngineProgrammer

Member Since 19 Aug 2012
Offline Last Active May 15 2013 04:11 PM

### In Topic: 3D algorithm

07 December 2012 - 09:10 AM

Thanks for the help, I've made a colorshader last year, but I didn't understood a single line of code what I was writing. Shaders are quite hard to understand for me.

How does DirectX render his transformations?
I just made a matrix class that can translate, scale and rotate. Tested it and it works.
Don't mind how I use the methods. It's just a testing project.
```Matrix matTranslate, matRotate, matScale, matWorld;
matTranslate.SetAsTranslate(-0.7f, -0.4f);
matRotate.SetAsRotate(80.0);
matScale.SetAsScale(0.5,0.5);
matWorld =  matRotate * matScale * matTranslate;
Matrix::SetAsWorld(hDC, matWorld);

Rectangle(hDC, -1, -1, 1, 1);
```

This is what I use for my transformations:
```Matrix::Matrix():
eM11(0.0f), eM12(0.0f), eM13(0.0f),
eM21(0.0f), eM22(0.0f), eM23(0.0f),
eM31(0.0f), eM32(0.0f), eM33(0.0f)
{
}

void Matrix::SetAsTranslate(float x, float y)
{
eM11 = 1.0f;
eM12 = 0.0f;
eM13 = 0.0f;
eM21 = 0.0f;
eM22 = 1.0f;
eM23 = 0.0f;
eM31 = x;
eM32 = y;
eM33 = 1.0f;
}

{
eM13 = 0.0f;
eM23 = 0.0f;
eM31 = 0.0f;
eM32 = 0.0f;
eM33 = 1.0f;
}

void Matrix::SetAsRotate(double degrees)
{
float radians = (float)(degrees/180 * M_PI);
eM13 = 0.0f;
eM23 = 0.0f;
eM31 = 0.0f;
eM32 = 0.0f;
eM33 = 1.0f;
}

void Matrix::SetAsScale(float x, float y)
{
eM11 = x;
eM12 = 0.0f;
eM13 = 0.0f;
eM21 = 0.0f;
eM22 = y;
eM23 = 0.0f;
eM31 = 0.0f;
eM32 = 0.0f;
eM33 = 1.0f;
}

Matrix operator*(const Matrix& ref1, const Matrix& ref2)
{
Matrix mat;
mat.eM11 = ref1.eM11 * ref2.eM11 + ref1.eM12 * ref2.eM21 + ref1.eM13 * ref2.eM31;
mat.eM12 = ref1.eM11 * ref2.eM12 + ref1.eM12 * ref2.eM22 + ref1.eM13 * ref2.eM32;
mat.eM13 = ref1.eM11 * ref2.eM13 + ref1.eM12 * ref2.eM23 + ref1.eM13 * ref2.eM33;
mat.eM21 = ref1.eM21 * ref2.eM11 + ref1.eM22 * ref2.eM21 + ref1.eM23 * ref2.eM31;
mat.eM22 = ref1.eM21 * ref2.eM12 + ref1.eM22 * ref2.eM22 + ref1.eM23 * ref2.eM32;
mat.eM23 = ref1.eM21 * ref2.eM13 + ref1.eM22 * ref2.eM23 + ref1.eM23 * ref2.eM33;
mat.eM31 = ref1.eM31 * ref2.eM11 + ref1.eM32 * ref2.eM21 + ref1.eM33 * ref2.eM31;
mat.eM32 = ref1.eM31 * ref2.eM12 + ref1.eM32 * ref2.eM22 + ref1.eM33 * ref2.eM32;
mat.eM33 = ref1.eM31 * ref2.eM13 + ref1.eM32 * ref2.eM23 + ref1.eM33 * ref2.eM33;

return mat;
}

void Matrix::SetAsWorld(HDC hDC, const Matrix& mat)
{
XFORM form;
form.eM11 = mat.eM11;
form.eM12 = mat.eM12;
form.eM21 = mat.eM21;
form.eM22 = mat.eM22;
form.eDx = mat.eM31;
form.eDy = mat.eM32;

SetWorldTransform(hDC, &form);
}
```

The calculations I've written on paper first with help from a book. So I didn't copied anything from the internet. I'm getting the hang of matrices very fast with this book, next chapter is linear transformations!

But indeed, I'm using GDI and it's getting pretty classic. But I really don't want to use a single external library. Because it's too "easy" then.. I'm not trying to be stubborn. Any suggestions how I avoid the classic functions? DirectX also must use a classic way or are they working very low level and code all their rendering themselves?

### In Topic: 3D algorithm

07 December 2012 - 07:15 AM

I will gladly post my progress but it will take a while, today I realized I better learn matrices through 2D and when I understand everything I'll change to 3D.

I'm making my own matrix class which will be supported with the function SetWorldTransform. This function works with XFORM but I'm not using this one. It's better to write my own calculations self so I can learn from it. When I got it all calculated I just put everything into an XFORM and transform the world. So when I understand the matrix and transform concept I go to 3D.

Or is there a better way to transform my object(rectangle, bitmap, etc)?
I know matrices needs to be used to transform such an object, but I mean, is there something else to transform my world with?

### In Topic: 4D Arrays?

07 December 2012 - 02:42 AM

4D "can" be visualized in 3D: http://en.wikipedia.org/wiki/Tesseract
The fourth dimension can called whatever you like, some people say it's time, some people say it's space and some say it's an object in itself.

Here is a nice link about how you project the 4D in 3D: http://steve.hollasc...s/chapter4.html
Four-dimensional geometry: http://steve.hollasc...s/chapter2.html

### In Topic: 3D algorithm

06 December 2012 - 10:23 PM

It's all learning purpose. You say that I first need to work with the CPU, how do I do that? How can I choose which one I can use to get my project running? I know the difference between both tho, cpu only does 1 thing at the time while a gpu does multiple things at the same time. But no idea when I'm using a cpu or a gpu.

If you're not sure, you're definitely using a CPU

You only "use" the GPU (at least the current generation) by programming little programs called shaders (in HLSL, or GLSL) which perform very specific tasks (e.g. transform vertices, or shade pixels). All the rest is done by the driver automatically. You don't actually write complete software on it. Everything that you code in C++ or C# or Java or whatever language, really, is done on your CPU.

Damn, I messed up my mind then. Thank you for clearing this out!

### In Topic: 3D algorithm

06 December 2012 - 09:27 PM

Thanks everyone!

Radikalizm, I'm not trying to make a commercial software renderer DirectX and OpenGL can't be beaten so I won't try to.
It's all learning purpose. You say that I first need to work with the CPU, how do I do that? How can I choose which one I can use to get my project running? I know the difference between both tho, cpu only does 1 thing at the time while a gpu does multiple things at the same time. But no idea when I'm using a cpu or a gpu.

DracoLacertae, thanks for the examples! So drawing lines isn't that hard to get in 3D Before I get on to it, I bought a math book which covers every mathematics what game programming concerns. So I hope to get a line or a 3D polygon on my screen today!

uglybdavis, nicely done!

PARTNERS