Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :)
Watch your vector Victor. :) Watch your vector Victor. :)
Watch your vector Victor. :)
Go Back  Xtreme Visual Basic Talk > > > Watch your vector Victor. :)


Reply
 
Thread Tools Display Modes
  #1  
Old 12-29-2003, 10:52 AM
Shrikes Shrikes is offline
Newcomer
 
Join Date: Dec 2003
Posts: 11
Default Watch your vector Victor. :)


Hello,
I have and x,y,z coordinate and 2 angles of rotation in degrees. Given this information how do I move forward say 3 units?

I have found all kinds of information on adding mutiplying and even determining the displacement between two points but nothing that will give me the second point given the first point and a displacment. It is probably right in front of me and just not sinking in.

Even if you can't help, thanks for taking the time to read my post.
Reply With Quote
  #2  
Old 12-29-2003, 11:05 AM
Optikal's Avatar
OptikalWatch your vector Victor. :) Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

You know the movement vector (determined by your 'angles of rotation') and the magnitude is the distance you wish to move (3 units). Just create a translation matrix out of this, and then multiply your world matrix by this translation matrix to get the new world matrix for this object (if your trying to move the camera do these calculation on the view matrix instead of the world matrix).
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #3  
Old 12-29-2003, 11:19 AM
Shrikes Shrikes is offline
Newcomer
 
Join Date: Dec 2003
Posts: 11
Default

Thanks very much for the reply. I try not to ask unless I am really stumpped so it is extremly appreciated.

What you said makes sence but doing it this way raises a question. Am I approaching my design wrong? (backwards)

I have wrapped a model and its matrix in an object. The object knows its x,y,x and all rotations. Each time I render I build a matrix for this object. Would it be better to do it the other way where the object only contains its matix and the x,y,z and rotation values are pulled from the matrix when needed?

I have included some the model object below. This is then wrapped in another object that would have non-model properties like weight, cost, container, damage etc.... This way the same model could be shared mutiple times.

Thanks again for your help. I am going to look in to how to pull info from a matix and possible answer my own question.





Public Class clsModel

' Properties
Public Name As String
Public x As Single = 0.0
Public y As Single = 0.0
Public z As Single = 0.0
Public XRotation As Single = 0.0
Public YRotation As Single = 0.0
Public ZRotation As Single = 0.0
Public scale As Single = 1.0

Private Mesh As Mesh = Nothing ' Our mesh object in sysmem
Private MeshMaterials() As Direct3D.Material ' Materials for our mesh
Private MeshTextures() As Texture ' Textures for our mesh
Private D3DDev As Direct3D.Device

' Methods
Public Sub New(ByRef LocalD3DDev As Direct3D.Device)
D3DDev = LocalD3DDev
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Function Load(ByVal sModelName As String) As Boolean

Try

Me.Name = sModelName

Dim sModelPath As String
sModelPath = Application.StartupPath & "\Models\" & sModelName & "\"

' Load Model
Dim materials As ExtendedMaterial() = Nothing
Mesh = Mesh.FromFile(sModelPath & sModelName & ".x", MeshFlags.SystemMemory, D3DDev, materials)

' Load Textures
If MeshTextures Is Nothing Then
' We need to extract the material properties and texture names
MeshTextures = New Texture(materials.Length) {}
MeshMaterials = New Direct3D.Material(materials.Length) {}
Dim i As Integer
For i = 0 To materials.Length - 1
MeshMaterials(i) = materials(i).Material3D
' Set the ambient color for the material (D3DX does not do this)
MeshMaterials(i).Ambient = MeshMaterials(i).Diffuse

' Create the texture
MeshTextures(i) = TextureLoader.FromFile(D3DDev, sModelPath & materials(i).TextureFilename)
Next i
End If

Return True
Catch

Return False

End Try

End Function

Public Function Render() As Boolean

Dim MatrixRot As New Matrix() ' this models matrix
MatrixRot.RotateYawPitchRoll(Me.YRotation, Me.XRotation, Me.ZRotation)

' Calculate Scale
Dim MatrixScale As New Matrix() ' this models matrix
MatrixScale.Scale(Me.scale, Me.scale, Me.scale)

' Calculate Postion
Dim MatrixPos As New Matrix()
MatrixPos.Translate(Me.x, Me.y, Me.z)

' Combine all calculations
D3DDev.Transform.World = Matrix.Multiply(Matrix.Multiply(MatrixRot, MatrixScale), MatrixPos)

' Display Loop
Dim i As Integer
For i = 0 To MeshMaterials.Length - 1
' Set the material and texture for this subset
D3DDev.Material = MeshMaterials(i)
D3DDev.SetTexture(0, MeshTextures(i))

' Draw the mesh subset
Mesh.DrawSubset(i)
Next i

Return True
End Function

End Class
Reply With Quote
  #4  
Old 12-29-2003, 01:31 PM
Shrikes Shrikes is offline
Newcomer
 
Join Date: Dec 2003
Posts: 11
Default

OK I think I understand enough to re-ask this question properly.

To move an object forward in relation to its rotation I realize I can use a rotation matrix first and then a transformation Matrix to move it forward in relation to its new orientation.

At this point each object would be positioned based on its own rotated coordinate system. How would I have any idea where these object would be in realation to each other for collision detection etc...

I realize something just hasn't clicked for me with this, please bare with me.
Reply With Quote
  #5  
Old 12-29-2003, 01:56 PM
Optikal's Avatar
OptikalWatch your vector Victor. :) Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

For collision detection typically a bounding-box or bounding-sphere is used, and they are tested to see if they overlap. For a bounding sphere collision-test all you have to do is calculate the distance between the two objects and test if its less than the sum of the bounding sphere radii, if so a collision occurs. For bounding-box the calculations are slightly different but you get the idea.
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #6  
Old 12-29-2003, 10:13 PM
Shrikes Shrikes is offline
Newcomer
 
Join Date: Dec 2003
Posts: 11
Default

Well I understand the different methods of collision detection what I don't understand is if I use different matrices for all of my objects reposition, rotate and scale them numerous times how will I retreive their location, rotation and scale later. Is this something I have to track separatly or can I pull the information from the matrix as well.

I did find how to retreive x,y,z via the m41,m42,m43 properties. but the others have over lapping mx properties that I was not sure how to distingush between. I know you generally do not write code for people but if you could show me what a simple move forward would look like in this object it might answer my question.

I have included my wrapper object if you see me doing anything odd let me know, I am really stuggling with this. All my hard work today has paid off though I have a much beter understanding of the Matrix now.

Code:
Public Class clsObject ' Exposed properties Public ID As Long Public Name As String Private lXRotation As Long = 0 Private lYRotation As Long = 0 Private lZRotation As Long = 0 Private sScale As Single = 1.0 Public ModelName As String ' Child object Private oModel As clsModel ' Objects Matrices Dim MatrixRot As New Matrix() Dim MatrixScale As New Matrix() Dim MatrixPos As New Matrix() ' Calculate Rotation Dim RotFactor As Single = (3.15 * 2.0) / 360.0 ' actual range from -3.15 to +3.15 ' Filtered Properties Public Property X() As Single Get X = MatrixPos.M41 End Get Set(ByVal Value As Single) MatrixPos.M41 = Value MatrixPos.Translate(Me.X, Me.y, Me.Z) End Set End Property Public Property Y() As Single Get Y = MatrixPos.M42 End Get Set(ByVal Value As Single) MatrixPos.M42 = Value MatrixPos.Translate(Me.X, Me.Y, Me.Z) End Set End Property Public Property Z() As Single Get Z = MatrixPos.M43 End Get Set(ByVal Value As Single) MatrixPos.M43 = Value MatrixPos.Translate(Me.X, Me.y, Me.Z) End Set End Property Public Property XRotation() Get XRotation = lXRotation End Get Set(ByVal Value) lXRotation = ForceBoundry(Value) End Set End Property Public Property YRotation() Get YRotation = lYRotation End Get Set(ByVal Value) lYRotation = ForceBoundry(Value) End Set End Property Public Property ZRotation() Get ZRotation = lZRotation End Get Set(ByVal Value) lZRotation = ForceBoundry(Value) End Set End Property Public Property Scale() As Single Get Scale = sScale End Get Set(ByVal Value As Single) sScale = Value MatrixScale.Scale(Me.Scale, Me.Scale, Me.Scale) End Set End Property Public Sub New() oModel = Nothing End Sub Protected Overrides Sub Finalize() oModel = Nothing MatrixRot = Nothing MatrixScale = Nothing MatrixPos = Nothing MyBase.Finalize() End Sub Public Sub MoveForward(ByVal Distance As Single) End Sub Public Sub MoveBackward(ByVal Distance As Single) End Sub Public Sub MoveLeft(ByVal Distance As Single) End Sub Public Sub MoveRight(ByVal Distance As Single) End Sub Public Sub Render(ByVal D3DDev As Device) If oModel Is Nothing Then oModel = New clsModel(D3DDev) oModel.Load(ModelName) End If MatrixRot.RotateYawPitchRoll(RotFactor * (Me.YRotation - 180), RotFactor * (Me.XRotation - 180), RotFactor * (Me.ZRotation - 180)) ' Combine all calculations D3DDev.Transform.World = Matrix.Multiply(Matrix.Multiply(MatrixRot, MatrixScale), MatrixPos) oModel.Render() End Sub Private Function ForceBoundry(ByVal Number As Long, Optional ByVal Minimum As Long = 0, Optional ByVal Maximum As Long = 360, Optional ByVal Wrap As Boolean = True) As Long If Wrap = True Then While Number > Maximum Number -= Maximum End While While Number < Minimum Number += Maximum End While Else If Number > Maximum Then Number = Maximum Else If Number < Minimum Then Number = Minimum End If End If End If Return Number End Function End Class
Reply With Quote
  #7  
Old 12-30-2003, 08:47 AM
Optikal's Avatar
OptikalWatch your vector Victor. :) Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

You should only need to use m41, m42, and m43 to do collision detection. Just create a bounding sphere/box at the origin denoted by m41, m42, m43 of your world matrix for that object, then perform collision detection on that.
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Watch Dog, Check if process is open Pandora API 3 05-23-2003 09:24 AM
Watch other computers Buzter Communications 1 03-24-2003 10:22 AM
Debug Watch help needed The Cleaner General 2 08-19-2001 12:04 PM
print debug watch Laurent General 5 05-30-2001 09:38 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :) Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :) Watch your vector Victor. :)
Watch your vector Victor. :)
Watch your vector Victor. :)
 
Watch your vector Victor. :)
Watch your vector Victor. :)
 
-->