Discussion:
Why isn't this translating?
(too old to reply)
Chris
2004-06-02 00:07:19 UTC
Permalink
I cannot figure out why this is not translating. I adapted this code from
something else(3D), to fit what I am doing,(2D). I can't seem to get my 2D
object to translate. It doesn't move. Here is the relevant code:

loadGeometry creates the object, oneFrameUpdate is called, then
oneFrameRender is called to draw a small filled in rectangle on the screen.

'This creates the rectangle
Private Sub loadGeometry()
Try
vbCar = New
VertexBuffer(GetType(CustomVertex.TransformedColored), 4, D3DDev, 0,
CustomVertex.TransformedColored.Format, Pool.Default)
Dim vc As CustomVertex.TransformedColored() =
CType(vbCar.Lock(0, 0), CustomVertex.TransformedColored())
Const iCBWidth As Integer = 12
Const iCBHeight As Integer = 6
vc(0) = New CustomVertex.TransformedColored(0 + 10, 86, 0, 1,
Drawing.Color.Black.ToArgb())
vc(1) = New CustomVertex.TransformedColored(iCBWidth + 10, 86,
1, 1, Drawing.Color.Black.ToArgb())
vc(2) = New CustomVertex.TransformedColored(0 + 10, 86 +
iCBHeight, 1, 1, Drawing.Color.Black.ToArgb())
vc(3) = New CustomVertex.TransformedColored(iCBWidth + 10, 86 +
iCBHeight, 1, 1, Drawing.Color.Black.ToArgb())
vbCar.Unlock()
Catch err As Exception
MsgBox("loadGeometry(): " + Chr(13) + Chr(13) + err.ToString())
Throw New Exception("could not complete loadGeometry()")
End Try
End Sub

'Creates the translation matrix
Public Sub oneFrameUpdate()
matCar1 = Matrix.Multiply(matCar1, Matrix.Translation(5, 0, 0))
End Sub

'Draws the object translated
Public Sub oneFrameRender()
D3DDev.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, _
Drawing.Color.White, 1.0F, 0)
D3DDev.BeginScene()
D3DDev.SetStreamSource(0, vbCar, 0)
D3DDev.VertexFormat = CustomVertex.TransformedColored.Format
D3DDev.Transform.World = matCar1
D3DDev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)
D3DDev.EndScene()
D3DDev.Present()
End Sub


Can anyone spot why it isnt translating?
Thanks!
Chris
Tom Miller [MS]
2004-06-02 02:06:28 UTC
Permalink
because you're using already transformed vertices.
--
- Tom Miller, Managed DirectX
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by Chris
I cannot figure out why this is not translating. I adapted this code from
something else(3D), to fit what I am doing,(2D). I can't seem to get my 2D
loadGeometry creates the object, oneFrameUpdate is called, then
oneFrameRender is called to draw a small filled in rectangle on the screen.
'This creates the rectangle
Private Sub loadGeometry()
Try
vbCar = New
VertexBuffer(GetType(CustomVertex.TransformedColored), 4, D3DDev, 0,
CustomVertex.TransformedColored.Format, Pool.Default)
Dim vc As CustomVertex.TransformedColored() =
CType(vbCar.Lock(0, 0), CustomVertex.TransformedColored())
Const iCBWidth As Integer = 12
Const iCBHeight As Integer = 6
vc(0) = New CustomVertex.TransformedColored(0 + 10, 86, 0, 1,
Drawing.Color.Black.ToArgb())
vc(1) = New CustomVertex.TransformedColored(iCBWidth + 10, 86,
1, 1, Drawing.Color.Black.ToArgb())
vc(2) = New CustomVertex.TransformedColored(0 + 10, 86 +
iCBHeight, 1, 1, Drawing.Color.Black.ToArgb())
vc(3) = New CustomVertex.TransformedColored(iCBWidth + 10, 86 +
iCBHeight, 1, 1, Drawing.Color.Black.ToArgb())
vbCar.Unlock()
Catch err As Exception
MsgBox("loadGeometry(): " + Chr(13) + Chr(13) + err.ToString())
Throw New Exception("could not complete loadGeometry()")
End Try
End Sub
'Creates the translation matrix
Public Sub oneFrameUpdate()
matCar1 = Matrix.Multiply(matCar1, Matrix.Translation(5, 0, 0))
End Sub
'Draws the object translated
Public Sub oneFrameRender()
D3DDev.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, _
Drawing.Color.White, 1.0F, 0)
D3DDev.BeginScene()
D3DDev.SetStreamSource(0, vbCar, 0)
D3DDev.VertexFormat = CustomVertex.TransformedColored.Format
D3DDev.Transform.World = matCar1
D3DDev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)
D3DDev.EndScene()
D3DDev.Present()
End Sub
Can anyone spot why it isnt translating?
Thanks!
Chris
Chris
2004-06-02 02:49:12 UTC
Permalink
Excuse my lack of knowledge...but how would I fix this? exchange
TransformedColored to PositionColored?
Thanks!
Chris
Post by Tom Miller [MS]
because you're using already transformed vertices.
--
- Tom Miller, Managed DirectX
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by Chris
I cannot figure out why this is not translating. I adapted this code from
something else(3D), to fit what I am doing,(2D). I can't seem to get my 2D
loadGeometry creates the object, oneFrameUpdate is called, then
oneFrameRender is called to draw a small filled in rectangle on the screen.
'This creates the rectangle
Private Sub loadGeometry()
Try
vbCar = New
VertexBuffer(GetType(CustomVertex.TransformedColored), 4, D3DDev, 0,
CustomVertex.TransformedColored.Format, Pool.Default)
Dim vc As CustomVertex.TransformedColored() =
CType(vbCar.Lock(0, 0), CustomVertex.TransformedColored())
Const iCBWidth As Integer = 12
Const iCBHeight As Integer = 6
vc(0) = New CustomVertex.TransformedColored(0 + 10, 86, 0, 1,
Drawing.Color.Black.ToArgb())
vc(1) = New CustomVertex.TransformedColored(iCBWidth + 10, 86,
1, 1, Drawing.Color.Black.ToArgb())
vc(2) = New CustomVertex.TransformedColored(0 + 10, 86 +
iCBHeight, 1, 1, Drawing.Color.Black.ToArgb())
vc(3) = New CustomVertex.TransformedColored(iCBWidth + 10, 86 +
iCBHeight, 1, 1, Drawing.Color.Black.ToArgb())
vbCar.Unlock()
Catch err As Exception
MsgBox("loadGeometry(): " + Chr(13) + Chr(13) +
err.ToString())
Post by Tom Miller [MS]
Post by Chris
Throw New Exception("could not complete loadGeometry()")
End Try
End Sub
'Creates the translation matrix
Public Sub oneFrameUpdate()
matCar1 = Matrix.Multiply(matCar1, Matrix.Translation(5, 0, 0))
End Sub
'Draws the object translated
Public Sub oneFrameRender()
D3DDev.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, _
Drawing.Color.White, 1.0F, 0)
D3DDev.BeginScene()
D3DDev.SetStreamSource(0, vbCar, 0)
D3DDev.VertexFormat = CustomVertex.TransformedColored.Format
D3DDev.Transform.World = matCar1
D3DDev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)
D3DDev.EndScene()
D3DDev.Present()
End Sub
Can anyone spot why it isnt translating?
Thanks!
Chris
Loading...