-
Apr 13th, 2013, 08:07 AM
#1
Thread Starter
Member
Custom mesh rotating and collision detect
We know how to rotate a mesh in threads before, huh?
But i just want to know this: Rotating the matrix, but if i want to rotate at specific point, or y-axis-based pararell line (3,0,3 and 3,1,3 rather than 1,0,1 and 1,1,1). I just can't figure out how, and i think using rotate and translate local coords might help.
And more, i'm bored seeing going through walls, guns, blablabla. I want the normal mode, not the ghost/god mode .
I have the basics: calculating the x/z distance between two object, if there's two human mesh moving (not flying) randomly on the ground.
And calculating the y distance between ball and the ground. We can know when it collisions with another.
And how can I code it? I have a roughly ground mesh.
-
Apr 13th, 2013, 08:09 AM
#2
Thread Starter
Member
Re: Custom mesh rotating and collision detect
And what is World1, world2, world3, texture1, texture2, ... in device.transform? Shortcut? if so how can i target them?
-
Apr 13th, 2013, 11:31 AM
#3
Re: Custom mesh rotating and collision detect
I don't get what you mean by rotating by a specific point. If you wanna rotate like for example just the y axis, just the x axis, or just the z axis, or any of the two, then just use them. If you wanna circle around a specific rotation point, then I believe you translate first then rotate.
I personally never worked with world2, world3, texture2, etc because I don't ever have multiple worlds on the screen at once, which is what I'm assuming its used for. So don't worry about em. As for collision, the only 3D collision code I have is a bounding box test but unfortunately its a little inaccurate. I was gonna try to use Rigid Body Collision Detection in 3D but it gets pretty complex. A more accurate 3D collision would be a Sweep Collision test, because it doesnt matter how fast the object goes, itll never go through the wall. So you could try Googling those to get ideas. Heres a Bounding Box collision function in 3D. You don't need the stupid Sprite structure to be honest. The arguements in Bounding Box could be rewritten to these variables, but I put it in a sprite structure cause it was easier: Obj1_MinX, Obj1_MinY, Obj1_MinZ, Obj1_MaxX, Obj1_MaxY, Obj1_MaxZ, Obj2_MinX, Obj2_MinY, Obj2_MinZ, Obj2_MaxX, Obj2_MaxY, Obj2_MaxZ, Obj1_Old_Position, Obj1_Position, Obj2_Old_Position, Obj2_Position
vb.net Code:
Public Structure Box3D
Public Min As Vector3
Public Max As Vector3
End Structure
Public Structure Sprite
Public Position As Vector3
Public Old_Position As Vector3
Public Bounding_Box As Box3D
End Structure
Public Function Bounding_Box_Test(ByVal Sprite_A As Sprite, ByVal Sprite_B As Sprite) As Boolean
Dim Box_A As Box3D
Dim Box_B As Box3D
With Sprite_A
Box_A.Min.X = .Old_Position.X + .Bounding_Box.Min.X
Box_A.Max.X = .Position.X + .Bounding_Box.Max.X
Box_A.Min.Y = .Old_Position.Y + .Bounding_Box.Min.Y
Box_A.Max.Y = .Position.Y + .Bounding_Box.Max.Y
Box_A.Min.Z = .Old_Position.Z + .Bounding_Box.Min.Z
Box_A.Max.Z = .Position.Z + .Bounding_Box.Max.Z
End With
With Sprite_B
Box_B.Min.X = .Old_Position.X + .Bounding_Box.Min.X
Box_B.Max.X = .Position.X + .Bounding_Box.Max.X
Box_B.Min.Y = .Old_Position.Y + .Bounding_Box.Min.Y
Box_B.Max.Y = .Position.Y + .Bounding_Box.Max.Y
Box_B.Min.Z = .Old_Position.Z + .Bounding_Box.Min.Z
Box_B.Max.Z = .Position.Z + .Bounding_Box.Max.Z
End With
'AxMin < BxMax and AxMax > BxMin
'AyMin < ByMax and AyMax > ByMin
'AzMin < BzMax and AzMax > BzMin
If ((Box_A.Min.X < Box_B.Max.X) And (Box_A.Max.X > Box_B.Min.X)) And _
((Box_A.Min.Y < Box_B.Max.Y) And (Box_A.Max.Y > Box_B.Min.Y)) And _
((Box_A.Min.Z < Box_B.Max.Z) And (Box_A.Max.Z > Box_B.Min.Z)) Then
Return True
End If
Return False
End Function
-
Apr 15th, 2013, 01:45 AM
#4
Thread Starter
Member
Re: Custom mesh rotating and collision detect
Sorry, it's a bit late reply. I have to done my school final test and after that i've updated my profile.
I'll draw this:
to make the problem more visually.
note that the line is not y axis, it is pararell with y axis (the y axis, of course is from 0,0,0 to 0,∞,0) and the line is 3,0,3 to 3,∞,3. They both have the same y.
Last edited by PAPYRON; Apr 15th, 2013 at 09:01 AM.
-
Apr 15th, 2013, 09:05 AM
#5
Re: Custom mesh rotating and collision detect
Yep I knew it. Translate then rotate and it just might work.
-
Apr 15th, 2013, 09:11 AM
#6
Thread Starter
Member
Re: Custom mesh rotating and collision detect
Ah you know, the last project i've updated on my previous thread is SniperEmu. It calculates the bullet move. So that i need accurate. I've been exploring the newton physics for days. Hae you tried this? And if you can give me something, a remark, or an advice, which physics lib is needed? or is that accurate? I think there's always inacurate, even in physx but it's small enough to ... true
-
Apr 16th, 2013, 02:16 AM
#7
Re: Custom mesh rotating and collision detect
Personally I like creating my own physics engines because, lord knows, they are just more fun rather than using someone elses, or some 3rd party library. I recommend you create your own because you learn a hell of a lot more. I already have tons of physics based example in my signature, although some are dated cause if I was to create the same projects today theyd be better. Written in VB6 and no doubt convertable to .NET if you want, I got rigid body kinematics 2D, DJ Turntable simulation, Newton Physics Simulation, and Friction Force. All of which you can find in my signature.
Now, you see the key to a decent physics engine is a number of things, like a decent and accurate integrator. The easiest to understand and quite possibly the most inaccurate is the Forward Euler Integrator. Although so easy a child can understand, its flawed and gets a lot worse as time progresses. The other integrators are better, such as Verlet, Velocity Verlet, Leap Frog, 2nd Order Runge Kutta, 3rd Order Runge Kutta, and my personal favorite cause its so damn accurate and looks cool yet complex, is 4th Order Runge Kutta.
Speaking of time, youll need an extremely accurate Timer, and the most accurate Timer API that I know of are the QueryPerformanceCounter, and QueryPerformanceFrequency APIs.
You'll also need an extremely accurate collision detection system as part of your physics engine. Now although Bounding box is easy to implement, both in 2D and 3D, its not as accurate as you want it to be. Especially if the object goes super fast. Rigid Body Collision to the rescue! And the beauty of it is the fact that it doesnt matter what shape your convex object is (keyword convex not concave), itll collide accurately down to the pixel and offset the object correctly as you want it! However, its sort of not enough because you still have fast moving objects. Another solution is to do a Sweep Collision Test. That way there, it doesn't matter if the object moves 1000 pixels per second, itll accurately collide into your object, like in this image here:
And no doubt you'll also need the key to physics, is collision response. Would you want your object to abruptly stop? Or would you want it to slide a little bit by giving it a little friction depending on the surface? Like Mario from the classic Super Mario Bros. He had a nice slide going. And if your Mario is on ice, you want him to have a nice slide going by adding less friction. These are just some examples of collision response. Rigid Body Kinematics is my personal favorite, because objects can rotate upon impact of another and look very realistic, even on simple polygon shapes. It gives them life. See Angry Birds for a nice Rigid Body Kinematic example. Exactly my point.
And of course the genesis of physics is...Gravity. Yea, so things can fall down. Its why physics was invened. Isaac Newton got hit in the head with an apple from a tree to spring up this radical idea. Now falling is cool, but you can make things jump, like again, Mario. Earth gravity alone is 9.78033 m/s². However if you want moon physics, theres also 1.622 m/s². But as things fall down, you are gonna wanna add a little air resistance as well. Because otherwise a feather and hammer could hit the ground at the same time when dropped from a building. Or if underwater, you could add density, so things take longer to hit the ground.
Now a physics engine aint a physics engine without mass. You will need mass. All your objects will need mass one way or another. Hell, the formula F = MA (Force = Mass * Acceleration) is a great example, which happens to be the formula for gravity. However this formula will not work on its own because youll need to integrate your objects as well. All those things tie together in a physics engine. Time, Mass, Acceleration, Velocity, Position, Direction, Collision... everything! Its the closest thing to being God as youre going to get.
Theres like a bunch of other things you can add to physics engines, such as torque, projectile motion, spring physics, cloth physics, wind, magnets, water waves... I mean I can go on and on. But its best you take a look at my examples for ideas. The best physics examples youll find online sadly happen to be written in C++. And no doubt you can convert it to .NET. I found a killer Rigid Body Tutorial which consisted of I think 8 programs written in C++, and the file name is Polycolly.zip if you can find it somewhere on Google cause the blasted link no longer exist, but if you can find it, thatll help you tremendously. Its an OpenGL based example but you can convert it to pure .NET or even DirectX. Hell I coverted one example into my pure VB Ridid Body Collision example. He also has one for fast moving objects. And steps it up to what looks like Angry Bird style Rigid Body Physics in example 7 and 8.
Id go into more detail on these topics, but they tend to get rather complex but I made it sorta fun for you to get a rough idea. So if you need to, Google up any of those. And believe me, itll open up so many doors its not even funny! Good luck to ya
-
Apr 17th, 2013, 04:35 AM
#8
Thread Starter
Member
Re: Custom mesh rotating and collision detect
-
Apr 17th, 2013, 04:38 AM
#9
Thread Starter
Member
Re: Custom mesh rotating and collision detect
The Newton link in your signalture, make me scared @@!
-
Apr 17th, 2013, 11:52 AM
#10
Re: Custom mesh rotating and collision detect
Why is that? If that makes you scared, then my NES emulator I wrote must be scarier o.O
-
Apr 18th, 2013, 04:19 AM
#11
Thread Starter
Member
Re: Custom mesh rotating and collision detect
That's a long time needed to understand the code! I'm a beginner, you know
-
Apr 19th, 2013, 03:32 PM
#12
Lively Member
Re: Custom mesh rotating and collision detect
Hope this helps
Code:
Public Class Form1
Dim Image1 As Bitmap
Dim BGround As Bitmap
Dim angle As Integer
Dim RunLoop As Boolean
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
BGround = New Bitmap("Images\Grass_1.png")
Image1 = New Bitmap("Images\Player_1.png")
Image1.MakeTransparent(Color.Black)
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'Background
e.Graphics.DrawImage(BGround, (150 - 60), (150 - 60), 60, 60)
e.Graphics.DrawImage(BGround, (150 + 60), (150 + 60), 60, 60)
e.Graphics.DrawImage(BGround, 150, 150, 60, 60)
'Location - Center Screen
e.Graphics.TranslateTransform(150, 150)
'Angle
e.Graphics.RotateTransform(angle)
'Argument 1 = Location -30, -30 to keep position true on rotate meaning image.size / 2 Argument 2 = Image size
e.Graphics.DrawImage(Image1, -30, -30, 60, 60)
End Sub
Private Sub GameLoop_Tick(sender As System.Object, e As System.EventArgs) Handles GameLoop.Tick
angle += 5
Me.Refresh()
End Sub
Private Sub btnLoop_Click(sender As System.Object, e As System.EventArgs) Handles btnLoop.Click
If RunLoop = False Then
btnLoop.Text = "Running"
RunLoop = True
GameLoop.Enabled = True
Else
btnLoop.Text = "Turned Off"
RunLoop = False
GameLoop.Enabled = False
End If
End Sub
End Class
-
Apr 19th, 2013, 09:58 PM
#13
Thread Starter
Member
Re: Custom mesh rotating and collision detect
No i mean DirectX, mholmes_3038.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|