Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 How to simulate transformed vts with untransformed

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
cbx Posted - Apr 05 2003 : 6:32:28 PM
I am thinking about creating a simulated direct draw api, that uses direct3d to draw untransformed polys on screen but heres the thing.

I am trying to setup a flat rectangular mesh on the screen using unproject. So that the user simply passes in screen coordanants and behind the scenes my api will store the vertexes as untransformed and lit vertex(s).

But I seem to be having a problem with the perspective view (i think). I can't quite get the untransformed and lit vertexes/polys to ack like they are transformed and lit.

I know, I know, why don't I just use transformed and lit vertexes and save my self the hassle? Because I want to be able to both simulate direct draw thru the api and at the same time have the ability to render untransformed and lit 3d objects on screen, all this without having to set the direct3d device to switch between transformed and lit vertexes and untransformed and lit vertexes.

anuyone have any ideas of how to use untransformed verts to simulate transformed verts? Or better yet a simple example code.
3   L A T E S T    R E P L I E S    (Newest First)
cbx Posted - Apr 06 2003 : 01:24:58 AM
I pretty much got it working but there are still some depth issues...

  
  
'Created by: X
'E-Mail: mailto:createdbyx@yahoo.com
'Web: http://www.createdbyx.com/
'Date: April 4, 2003
'=============================================
  
Public Class Form1  
    Inherits System.Windows.Forms.Form  
  
  
    Private mobjGraphics As DX9ToolsR4.DX9Graphics  
    Private mobjFont As Direct3D.Font  
    Private Verts(4) As Direct3D.CustomVertex.PositionColoredTextured  
    Private VertRect(3) As Direct3D.CustomVertex.PositionColoredTextured  
    Private mobjSize As SizeF = New SizeF(320, 240)  
    Private msngDepth As Single = 0  
    Private mobjPrevMouse As Vector2  
    Private Tex As Direct3D.Texture  
    Private mblnShowLine As Boolean = True
    Private mblnRotate As Boolean = False
    Private mintRotation As Integer = 0  
  
#Region " Windows Form Designer generated code "  
  
    Public Sub New()  
        MyBase.New()  
  
        'This call is required by the Windows Form Designer.  
        InitializeComponent()  
  
        'Add any initialization after the InitializeComponent() call  
  
    End Sub
  
    'Form overrides dispose to clean up the component list.  
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)  
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()  
            End If
        End If
        MyBase.Dispose(disposing)  
    End Sub
  
    'Required by the Windows Form Designer  
    Private components As System.ComponentModel.IContainer  
  
    'NOTE: The following procedure is required by the Windows Form Designer  
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.  
    Friend WithEvents tmrTimer As System.Windows.Forms.Timer  
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()  
        Me.components = New System.ComponentModel.Container()  
        Me.tmrTimer = New System.Windows.Forms.Timer(Me.components)  
        '  
        'tmrTimer  
        '  
        '  
        'Form1  
        '  
        Me.AutoScaleBaseSize = New System.Drawing.Size(10, 22)  
        Me.ClientSize = New System.Drawing.Size(586, 464)  
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog  
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"  
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen  
        Me.Text = "Form1"  
  
    End Sub
  
#End Region  
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
        Me.Show()  
        Me.Focus()  
        ResizeForm(New Size(640, 480))  
  
        mobjGraphics = New DX9ToolsR4.DX9Graphics(Me)  
        With mobjGraphics.Device  
            .RenderState.Lighting = True
            .RenderState.FillMode = DirectX.Direct3D.FillMode.Solid  
            .RenderState.ShadeMode = DirectX.Direct3D.ShadeMode.Gouraud  
            .RenderState.CullMode = DirectX.Direct3D.Cull.None  
            .RenderState.Ambient = Color.White  
        End With
  
        With mobjGraphics.Camera  
            .AspectRatio = CSng(Me.ClientSize.Width / Me.ClientSize.Height)  
            .SetPosition(DX9ToolsR4.Camera.SetVector.Z, CSng(Me.ClientSize.Width) / 2)  
            .NearPlane = 1  
            .FarPlane = 1000  
        End With
        mobjFont = New Direct3D.Font(mobjGraphics.Device, Me.Font)  
  
        Tex = Direct3D.TextureLoader.FromFile(mobjGraphics.Device, "../exp.png")  
  
        SetupVerts(0, 0)  
        SetupVertRect(mobjSize.Width / 2, mobjSize.Height / 2)  
    End Sub
  
    Private Sub SetupVerts(ByVal X As Single, ByVal Y As Single)  
        Dim D As Direct3D.Device  
        Dim Half As SizeF  
  
        D = mobjGraphics.Device  
        Half = New SizeF(mobjSize.Width / 2, mobjSize.Height / 2)  
        Verts(0) = New Direct3D.CustomVertex.PositionColoredTextured(ToObjSpace(D, X - Half.Width, Y - Half.Height, msngDepth), Color.White.ToArgb, 0, 0)  
        Verts(1) = New Direct3D.CustomVertex.PositionColoredTextured(ToObjSpace(D, X + Half.Width, Y - Half.Height, msngDepth), Color.White.ToArgb, 0, 0)  
        Verts(2) = New Direct3D.CustomVertex.PositionColoredTextured(ToObjSpace(D, X + Half.Width, Y + Half.Height, msngDepth), Color.White.ToArgb, 0, 0)  
        Verts(3) = New Direct3D.CustomVertex.PositionColoredTextured(ToObjSpace(D, X - Half.Width, Y + Half.Height, msngDepth), Color.White.ToArgb, 0, 0)  
        Verts(4) = New Direct3D.CustomVertex.PositionColoredTextured(ToObjSpace(D, X - Half.Width, Y - Half.Height, msngDepth), Color.White.ToArgb, 0, 0)  
    End Sub
  
    Private Sub SetupVertRect(ByVal X As Single, ByVal Y As Single)  
        Dim D As Direct3D.Device  
        Dim Half As SizeF  
        Dim V As Vector3  
  
        D = mobjGraphics.Device  
        Half = New SizeF(256, 256)  
        V = ToObjSpace(D, X - Half.Width, Y + Half.Height, msngDepth)  
        VertRect(0) = New Direct3D.CustomVertex.PositionColoredTextured(V, Color.White.ToArgb, 0, 1)  
        V = ToObjSpace(D, X - Half.Width, Y - Half.Height, msngDepth)  
        VertRect(1) = New Direct3D.CustomVertex.PositionColoredTextured(V, Color.White.ToArgb, 0, 0)  
        V = ToObjSpace(D, X + Half.Width, Y + Half.Height, msngDepth)  
        VertRect(2) = New Direct3D.CustomVertex.PositionColoredTextured(V, Color.White.ToArgb, 1, 1)  
        V = ToObjSpace(D, X + Half.Width, Y - Half.Height, msngDepth)  
        VertRect(3) = New Direct3D.CustomVertex.PositionColoredTextured(V, Color.White.ToArgb, 1, 0)  
    End Sub
  
    Private Sub ResizeForm(ByVal S As Size)  
        Me.Size = S  
        Me.Size = New Size(S.Width + (Me.Width - Me.ClientSize.Width), _  
                           S.Height + (Me.Height - Me.ClientSize.Height))  
    End Sub
  
    Private Sub SetupLights(ByVal Dev As Direct3D.Device)  
        Dim L As Direct3D.Light = Dev.Lights(0)  
  
        L = LightHelpers.CreateDirectionalLight(Color.White, DX9ToolsR4.Direction.Z)  
    End Sub
  
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint  
        Dim Msg As String
        Dim Mat As Direct3D.Material  
        Dim MT As Matrix  
        Dim Rad As Single
  
        Rad = Direct3D.Geometry.DegreeToRadian(mintRotation)  
        With mobjGraphics  
            .Clear()  
            .Device.BeginScene()  
  
            SetupLights(.Device)  
  
  
            ' draw line strip  
            Mat.Ambient = Color.White  
            Mat.Diffuse = Mat.Ambient  
            .Device.Material = Mat  
            .Device.VertexFormat = Verts(0).Format  
  
  
            ' Blend a Texture with Vertex Color  
            .Device.TextureState(0).ColorOperation = Direct3D.TextureOperation.Modulate  
            .Device.TextureState(0).ColorArgument1 = Direct3D.TextureArgument.TextureColor  
            .Device.TextureState(0).ColorArgument2 = Direct3D.TextureArgument.Diffuse  
            .Device.TextureState(0).AlphaOperation = Direct3D.TextureOperation.SelectArg1  
            .Device.TextureState(0).AlphaArgument1 = Direct3D.TextureArgument.TextureColor  
            .Device.SamplerState(0).MinFilter = Direct3D.TextureFilter.Linear  
            .Device.SamplerState(0).MagFilter = Direct3D.TextureFilter.Linear  
            .Device.SamplerState(0).MipFilter = Direct3D.TextureFilter.Linear  
            .Device.SamplerState(0).AddressU = Direct3D.TextureAddress.Wrap  
            .Device.SamplerState(0).AddressV = Direct3D.TextureAddress.Wrap  
  
  
            .Device.Transform.World = Matrix.Identity  
  
            'draw center image  
            SetupVertRect(mobjSize.Width / 2, mobjSize.Height / 2)  
            .Device.SetTexture(0, Tex)  
            .Device.RenderState.FillMode = DirectX.Direct3D.FillMode.Solid  
            .Device.DrawUserPrimitives(DirectX.Direct3D.PrimitiveType.TriangleStrip, 2, VertRect)  
            .Device.SetTexture(0, Nothing)  
            .Device.RenderState.FillMode = DirectX.Direct3D.FillMode.WireFrame  
            .Device.DrawUserPrimitives(DirectX.Direct3D.PrimitiveType.TriangleStrip, 2, VertRect)  
  
  
  
            If mblnShowLine Then
                If mblnRotate Then
                    MT = Matrix.Identity  
                    MT.RotateYawPitchRoll(Rad, Rad, Rad)  
                    .Device.Transform.World = MT  
                End If
  
                .Device.SetTexture(0, Nothing)  
                .Device.DrawUserPrimitives(DirectX.Direct3D.PrimitiveType.LineStrip, 4, Verts)  
  
            Else
  
                SetupVertRect(mobjPrevMouse.X, mobjPrevMouse.Y)  
  
                If mblnRotate Then
                    MT = Matrix.Identity  
                    MT.RotateYawPitchRoll(rad, rad, rad)  
                    .Device.Transform.World = MT  
                End If
  
                .Device.SetTexture(0, Tex)  
                .Device.RenderState.FillMode = DirectX.Direct3D.FillMode.Solid  
                .Device.DrawUserPrimitives(DirectX.Direct3D.PrimitiveType.TriangleStrip, 2, VertRect)  
                .Device.SetTexture(0, Nothing)  
                .Device.RenderState.FillMode = DirectX.Direct3D.FillMode.WireFrame  
                .Device.DrawUserPrimitives(DirectX.Direct3D.PrimitiveType.TriangleStrip, 2, VertRect)  
  
            End If
  
            '---------------  
  
            Msg = mobjPrevMouse.ToString & vbCrLf & "------------------------------" & vbCrLf  
            Msg &= mobjSize.ToString & vbCrLf  
            Msg &= "Depth: " & msngDepth.ToString & vbCrLf  
            Msg &= "Show Line: " & mblnShowLine.ToString & vbCrLf  
            Msg &= "Rotating: " & mblnRotate.ToString & vbCrLf  
  
            mobjFont.DrawText(Msg, Me.ClientRectangle, Direct3D.DrawTextFormat.Top Or Direct3D.DrawTextFormat.Left, Color.White)  
  
            .Device.EndScene()  
            .Present()  
        End With
  
    End Sub
  
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove  
        Dim V As Vector3  
        Dim vp As Direct3D.Viewport  
  
        If mobjGraphics Is Nothing Then Exit Sub
  
        mobjPrevMouse = New Vector2(e.X, e.Y)  
        If mblnShowLine Then
            SetupVerts(mobjPrevMouse.X, mobjPrevMouse.Y)  
        Else
            SetupVertRect(mobjPrevMouse.X, mobjPrevMouse.Y)  
        End If
        Form1_Paint(Nothing, Nothing)  
    End Sub
  
    Public Shared Function ToObjSpace(ByVal Dev As Direct3D.Device, ByVal X As Single, ByVal Y As Single, ByVal Depth As Single) As Vector3  
        Dim vNear, vFar As Vector3  
  
        vNear = New Vector3(X, Y, 0)  
        vNear.Unproject(Dev.Viewport, Dev.Transform.Projection, Dev.Transform.View, Dev.Transform.World)  
  
        vFar = New Vector3(X, Y, 1)  
        vFar.Unproject(Dev.Viewport, Dev.Transform.Projection, Dev.Transform.View, Dev.Transform.World)  
        vFar.Subtract(vNear)  
  
        Return Vector3.Lerp(vNear, vFar, Depth)  
    End Function
  
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown  
        Select Case e.KeyCode  
            Case Keys.Left  
                mobjSize.Width -= 1  
  
            Case Keys.Right  
                mobjSize.Width += 1  
  
            Case Keys.Up  
                mobjSize.Height -= 1  
  
            Case Keys.Down  
                mobjSize.Height += 1  
  
            Case Keys.A  
                msngDepth += CSng(0.01)  
  
            Case Keys.Z  
                msngDepth -= CSng(0.01)  
  
            Case Keys.L  
                mblnShowLine = Not mblnShowLine  
  
            Case Keys.R  
                mblnRotate = Not mblnRotate  
                If mblnRotate Then
                    tmrTimer.Start()  
                Else
                    tmrTimer.Stop()  
                    mintRotation = 0  
                End If
        End Select
  
        If mblnShowLine Then
            SetupVerts(mobjPrevMouse.X, mobjPrevMouse.Y)  
        Else
            SetupVertRect(mobjPrevMouse.X, mobjPrevMouse.Y)  
        End If
        Form1_Paint(Nothing, Nothing)  
        Application.DoEvents()  
    End Sub
  
    Private Sub tmrTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrTimer.Tick  
        mintRotation += 5  
        If mintRotation > 359 Then mintRotation = mintRotation - 360  
        Form1_Paint(Nothing, Nothing)  
    End Sub
End Class  
  
  


Any ideas on how to fix the code to make it able to rotate the verts and not have them dissapear? I have included the sample code exe here ...

Brinkster does not allow file leeching so here first
http://www10.brinkster.com/cbx/indexb.htm" target="_blank">http://www10.brinkster.com/cbx/indexb.htm

... then type this address into the address bar.
http://www10.brinkster.com/cbx/unproject.zip" target="_blank">http://www10.brinkster.com/cbx/unproject.zip

you should be able to download the file then.
cbx Posted - Apr 06 2003 : 12:45:06 AM
I am using DirectX9 and VB.NET.

I've considerd using the sprite obj in DX9, but it does not quite do everything I want it to.

For example with direct draw you can specify a destination rect and a texture source rect. but with the sprite object you can only specify the source rect, and then you would have to do calculatations for the scale vector to scale it to the dimention of the destination rect you want.

Using the sprite obj also would not allow me to rotate the obj in 3d if I wanted to. It would act more like a billboard that always faces the player.

Actually What I wanted to do was this ...

http://rookscape.com/vbgaming/tutBT.php

But unfortunatly the direct3d9 device settexture method does not allow a direct draw surface to be passed as a parameter, it only accepts a BaseTexture or inherited class. Which is why I am trying to get the vector3.unproject to return an acruate

I know there can be a speed penalty when switching between vertex formats during game play, which is why I am trying to do what I am without having to use more than one vert format.

quote:
Originally posted by Eric Coleman

For my game, I use untransformed data for almost everything excpet for the menus, text, and sometimes the mouse, which use transformed and lit vertices. So why not just use both types? Are you using Directx 8? If so, then why not use the sprite object?

Eric Coleman Posted - Apr 05 2003 : 8:50:18 PM
For my game, I use untransformed data for almost everything excpet for the menus, text, and sometimes the mouse, which use transformed and lit vertices. So why not just use both types? Are you using Directx 8? If so, then why not use the sprite object?

VBGamer © Go To Top Of Page
This page was generated in 0.94 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.