Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Rotating world cuts object

Started by seblon Sep 27, 2010 at 2:52 PM 0 replies 850+ views
Original Post
seblon
seblon
Hello,
i want to rotate a triangle(or all the world) but something is wrong with the "depth".

Here are two screenshots:
http://stne.net/img/screenshots/foren/gamedev/tri1.jpg
one second later:
http://stne.net/img/screenshots/foren/gamedev/tri2.jpg

its seems, there is a magic gray wall, but that should be only the cleared background.

Does anybody have an idea?

Here's my code:

Imports System.Runtime.InteropServicesModule Program	Public form As RenderForm	Public Device As Device	'Public vertices As VertexBuffer	'Public vertexDecl As VertexDeclaration	Public p As PresentParameters	Dim rt As TRenderContext	Public VertList As New List(Of Vertex)	Public decl As VertexDeclaration	Public _VertBuffer As VertexBuffer	Public _lineVertBuffer As VertexBuffer	Public Sub InitDevice()		OnResize(Nothing, Nothing)		CreateScene()	End Sub	Public linedecl As VertexDeclaration	'Public vFormat As VertexFormat = VertexFormat.Position Or VertexFormat.Diffuse	Public mm As Mesh	Public Sub CreateScene()		mm = Mesh.CreateBox(Device, 2, 3, 4)		decl = New VertexDeclaration(Device, New VertexElement() {New VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0), New VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), VertexElement.VertexDeclarationEnd})		linedecl = New VertexDeclaration(Device, New VertexElement() {New VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0), New VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), VertexElement.VertexDeclarationEnd})		_VertBuffer = New VertexBuffer(Device, Marshal.SizeOf(GetType(Vertex)) * 6, Usage.WriteOnly, VertexFormat.None, Pool.Managed)		Dim z As Single = 0.5		Dim offset As New Vector4(0.0, 0, -0.5, -20)		_VertBuffer.Lock(0, 0, LockFlags.None).WriteRange(New Vertex() {		New Vertex(Color.Red.ToArgb, New Vector4(0.0F, 0.5F, z, 1) + offset),		New Vertex(Color.Green.ToArgb, New Vector4(0.5F, -0.5F, z, 1) + offset),		New Vertex(Color.Blue.ToArgb, New Vector4(-0.5F, -0.5F, z, 1) + offset),		New Vertex(Color.Yellow.ToArgb, New Vector4(0.0F, 0.5F, z + 2, 1) + offset),		New Vertex(Color.Pink.ToArgb, New Vector4(0.5F, -0.5F, z + 2, 1) + offset),		New Vertex(Color.Cyan.ToArgb, New Vector4(-0.5F, -0.5F, z + 2, 1) + offset)})		_VertBuffer.Unlock()		Dim ar As Vertex()		Dim list As New ArrayList		Dim v1 As Single = -1.5		Dim v2 As Single = 1.5		For i As Single = v1 To v2 Step 0.1			list.Add(New Vertex(Color.Yellow.ToArgb, New Vector4(i, v1, 0, 1)))			list.Add(New Vertex(Color.Yellow.ToArgb, New Vector4(i, v2, 0, 1)))			list.Add(New Vertex(Color.Yellow.ToArgb, New Vector4(v1, i, 0, 1)))			list.Add(New Vertex(Color.Yellow.ToArgb, New Vector4(v2, i, 0, 1)))			list.Add(New Vertex(Color.Orange.ToArgb, New Vector4(0, v1, i, 1)))			list.Add(New Vertex(Color.Orange.ToArgb, New Vector4(0, v2, i, 1)))			list.Add(New Vertex(Color.Orange.ToArgb, New Vector4(0, i, v1, 1)))			list.Add(New Vertex(Color.Orange.ToArgb, New Vector4(0, i, v2, 1)))			list.Add(New Vertex(Color.Brown.ToArgb, New Vector4(v1, 0, i, 1)))			list.Add(New Vertex(Color.Brown.ToArgb, New Vector4(v2, 0, i, 1)))			list.Add(New Vertex(Color.Brown.ToArgb, New Vector4(i, 0, v1, 1)))			list.Add(New Vertex(Color.Brown.ToArgb, New Vector4(i, 0, v2, 1)))		Next		ar = list.ToArray(GetType(Vertex))		LineCount = ar.Length		_lineVertBuffer = New VertexBuffer(Device, Marshal.SizeOf(GetType(Vertex)) * list.Count, Usage.WriteOnly, VertexFormat.None, Pool.Managed)		_lineVertBuffer.Lock(0, 0, LockFlags.None).WriteRange(ar)		_lineVertBuffer.Unlock()	End Sub	Public LineCount As Integer	Private f2 As Form2	Public Sub Main()		f2 = New Form2		f2.Show()		form = New RenderForm("title")		AddHandler form.ResizeEnd, AddressOf OnResize		form.Show()		InitDevice()		'Dim surf As Surface = Surface.CreateDepthStencil(Device, form.ClientSize.Width, form.ClientSize.Height, Format.D16, MultisampleType.None, 0, False)		'Device.SetRenderTarget(0, surf)		CreateScene()		MessagePump.Run(form, AddressOf AppLoop)		For Each item As IDisposable In ObjectTable.Objects			item.Dispose()		Next	End Sub	Public Sub DisposeDevice()		Device.Dispose()	End Sub	Public Sub OnResize(ByVal sender As Object, ByVal e As EventArgs)		p = New PresentParameters		p.BackBufferWidth = form.ClientSize.Width		p.BackBufferHeight = form.ClientSize.Height		p.Windowed = True		p.BackBufferCount = 2		p.Multisample = MultisampleType.FourSamples		'p.MultisampleQuality = 2		'p.PresentFlags=		p.BackBufferFormat = Format.X8R8G8B8		p.EnableAutoDepthStencil = True		p.AutoDepthStencilFormat = Format.D16		p.SwapEffect = SwapEffect.Discard		If Device Is Nothing Then			Device = New Device(New Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, p)		End If		Device.Reset(p)		Device.SetRenderState(RenderState.Lighting, False)		'Device.SetRenderState(RenderState.ZEnable, ZBufferType.UseZBuffer)		'Device.SetRenderState(RenderState.ZEnable, True)		Device.SetRenderState(RenderState.CullMode, Cull.None)		'Device.SetRenderState(RenderState.ZFunc, Compare.Always)		'Device.SetRenderState(RenderState.FillMode, FillMode.Wireframe)	End Sub	Public Function DegToRad(ByVal deg As Single) As Single		Return deg * (Math.PI / 180)	End Function	Dim rindex As Single = 0.0F	Public Sub AppLoop()		form.Text = Now		'Device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.DarkGray, 1, Integer.MaxValue)		Device.Clear(ClearFlags.Target, Color.DarkGray, 1, 0)		Device.Clear(ClearFlags.ZBuffer, Color.DarkGray, 1, 0)		Device.BeginScene()		Device.SetStreamSource(0, _lineVertBuffer, 0, Marshal.SizeOf(GetType(Vertex)))		Device.VertexDeclaration = linedecl		Device.DrawPrimitives(PrimitiveType.LineList, 0, LineCount)		'mm.DrawSubset(0)		Dim mat As Matrix = Matrix.Identity		'view += Matrix.LookAtRH(Form2.Eye, Form2.LooksAt, Form2.CameraUp)		'view += Matrix.LookAtRH(Form2.Eye, Vector3.Zero, Form2.CameraUp)		mat += Matrix.RotationY(rindex)		'view += Matrix.PerspectiveFovRH(DegToRad(45), 0.5, 0.1,  1000)		'Device.SetTransform(TransformState.Projection, Matrix.RotationY(rindex))		Dim pers As Matrix = Matrix.PerspectiveFovLH(DegToRad(45), form.ClientSize.Width / form.ClientSize.Height, -1, 100)		Dim world As Matrix = Matrix.Identity		'world += Matrix.RotationY(rindex)		'Device.SetTransform(TransformState.World, view)		Device.SetTransform(TransformState.World, mat)	'simeple rotate of the world		'Device.SetTransform(TransformState.Projection, pers)		'Device.SetTransform(TransformState.View, Matrix.LookAtRH(New Vector3(0.0F, 0.5F, 100), New Vector3(0.0F, 0.5F, 0.5), New Vector3(0, 1, 0)))		rindex += 0.0001		'Device.SetTransform(TransformState.Projection, proj)		Device.SetStreamSource(0, _VertBuffer, 0, Marshal.SizeOf(GetType(Vertex)))		Dim matr As Matrix = Matrix.Identity		'matr.Translation(2, 0.1, 77)		'Device.SetTransform(TransformState.View, matr)		Device.VertexDeclaration = decl		Device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1)		'Device.SetTransform(TransformState.World, world + Matrix.Translation(0, 0, 2))		'Device.DrawPrimitives(PrimitiveType.TriangleList, 1, 1)		Device.EndScene()		Device.Present()	End SubEnd Module<System.Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _Public Structure Vertex	Public Position As Vector4	Public Color As Integer	Public Sub New(ByVal color As Integer, ByVal Position As Vector4)		Me.Position = Position		Me.Color = color	End SubEnd Structure


Greetings
seblon
seblon
I think, i've found the matter. It's the same like in this post:
http://www.gamedev.net/community/forums/topic.asp?topic_id=564473

Greetings

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.