Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 10 August 2005 - 06:21 AM
Posted 10 August 2005 - 06:52 AM
public static Matrix3 FromZAxis(Vector3 zAxis)
{
zAxis.Normalize();
Vector3 yAxis;
if(zAxis.X == 0 && zAxis.Z == 0)
{
yAxis = new Vector3(-zAxis.Y, 0, 0);
}
else
{
yAxis = new Vector3(0, 1, 0);
}
Vector3 xAxis = yAxis.Cross(zAxis);
xAxis.Normalize();
yAxis = xAxis.Cross(zAxis);
yAxis.Normalize();
yAxis = -yAxis;
return new Matrix3(xAxis, yAxis, zAxis);
}
Posted 10 August 2005 - 07:29 AM
Posted 10 August 2005 - 08:08 AM
Private Function RayCamera(ray As Vector3) As Vector3
Dim m As Matrix33
Dim cross As Vector3
Dim up As Vector3
up.X = 0
up.Y = 0
up.Z = 1
cross = Vector3CrossProduct(up, CamVect)
m.m11 = CamVect.X
m.m12 = CamVect.Y
m.m13 = CamVect.Z
m.m21 = up.X
m.m22 = up.Y
m.m23 = up.Z
m.m31 = cross.X
m.m32 = cross.Y
m.m33 = cross.Z
RayCamera = MatrixVectorMultiply3(m, ray)
End Function
Posted 10 August 2005 - 09:37 AM
Posted 10 August 2005 - 09:48 AM
Public Sub RenderPixel(hdc As Long, X As Long, Y As Long)
Dim ax As Long, ay As Long
ax = X - (Width / 2)
ay = Y - (Height / 2)
Dim c As RGBA128
'trace ray
Dim ray As Vector3
Dim pos As Vector3
pos.X = Cam.X
pos.Y = Cam.Y
pos.Z = Cam.Z
'ray
ray.X = ax
ray.Y = FOV
ray.Z = ay
ray = NormalizeVector(ray)
ray = RayCamera(ray)
'trace
c = TraceRay(ray, pos, True) 'goes to previous part of code
'set pixel
Dim fc As RGBA32
fc = RGBA128toRGBA32©
SetPixel hdc, X, Height - Y - 1, RGB(fc.R, fc.G, fc.b)
End Sub
Posted 11 August 2005 - 06:37 AM
Public Function MatrixVectorMultiply3(m1 As Matrix33, m2 As Vector3) As Vector3
MatrixVectorMultiply3.X = (m1.m11 * m2.X) + (m1.m12 * m2.Y) + (m1.m13 * m2.Z)
MatrixVectorMultiply3.Y = (m1.m21 * m2.X) + (m1.m22 * m2.Y) + (m1.m23 * m2.Z)
MatrixVectorMultiply3.Z = (m1.m31 * m2.X) + (m1.m32 * m2.Y) + (m1.m33 * m2.Z)
End Function
Private Function RayCamera(ray As Vector3) As Vector3
Dim m As Matrix33
Dim yaxis As Vector3, xaxis As Vector3 'zaxis=camvect
yaxis.X = 0
yaxis.Y = 0
yaxis.Z = 1
xaxis = Vector3CrossProduct(yaxis, CamVect)
xaxis = NormalizeVector(xaxis)
yaxis = Vector3CrossProduct(xaxis, CamVect)
yaxis = NormalizeVector(yaxis)
yaxis.X = -yaxis.X
yaxis.Y = -yaxis.Y
yaxis.Z = -yaxis.Z
'create matrix
m.m11 = xaxis.X: m.m12 = xaxis.Y: m.m13 = xaxis.Z
m.m21 = yaxis.X: m.m22 = yaxis.Y: m.m23 = yaxis.Z
m.m31 = CamVect.X: m.m32 = CamVect.Y: m.m33 = CamVect.Z
'multiply
RayCamera = MatrixVectorMultiply3(m, ray)
RayCamera = NormalizeVector(RayCamera)
End Function
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.