Collision detection code written(help needed)
-
@
import Qt 4.7Rectangle {
id: rect
width: 650; height: 400
color: "#d7d1d1"Image { id: image1 property variant direction : "right" x: 51 y: 30 width: 100 height: 100 transformOrigin: "Center" z: 26 rotation: -360 scale: 1 source: "qrc:/new/prefix1/2-Pound-Medicine-Ball.jpg" SequentialAnimation on x { loops: Animation.Infinite NumberAnimation { to: rect.width - 10; duration: 2000 } PropertyAction { target: image1; property: "direction"; value: "left" } NumberAnimation { to: 10; duration: 2000 } PropertyAction { target: image1; property: "direction"; value: "right" } } } Image { id: image2 property variant direction : "right" x: 364 y: 30 width: 100 height: 100 source: "qrc:/new/prefix1/948709.jpg" } function collisiondetection(x1,x2,y1,y2) { if(image1.x1>image2.x1 && image1.y1>image2.y1) return; }
}@
regards
imrrk[Edit: properly mark up code, Tobias Hunger]
-
your code is totally unreadable, you should use markup
-
kxyu..please wait i will do it
-
kxyu..how to do that
-
put @ on the left and on the right of your code
-
hey kxyu,
now the code is in readable format..so please help me out..with the code..
-
I took the time to properly mark up your code, but I still do not get what do you want us to do for you. Are we supposed to fix it? It would be helpful to know what you want it to do.
Here are a couple fo things I noticed while marking up your code: I am not a Javascript expert, but your collision detection code does not return anything, does it? The condition of that method seems to be totally broken, too... Why do you rotate by -360 degrees? Isen't that the same as no rotation? Is collisiondetection actually used anywhere?
-
hi tobias,,,i am also new to qml and javascript...i want to do collision detection to happen when the two images or rectangles or circles collide with each other...ya thats true that it does not return anything..because i am stuck in between..so i would be thankful to u if u help me out..
Regards
imrrk -
Did you really read what others told you in the other thread you created:
"collision detection using qt quick":http://developer.qt.nokia.com/forums/viewthread/2912
No answer from yours there! QtK
Did you start a search on "collision detection" or use the tag search on "colission detection":http://developer.qt.nokia.com/search/tag/collision+detection?
e.g. read this:
"Regarding QML":http://developer.qt.nokia.com/forums/viewthread/1695 -
hello volver....
i have checked ..it ,but its not concrete..solution....so i started this thread...can you provide me some fundamentals about this collision detection abt two bodies and also the bodies should respond to the collision..now i have managed to detect collision and the bodies are responding..but not in a proper flow....so if you would help me out..i will be very thanful to you...regards
imrrk -
No one can know that if you don't tell us!
Regarding the collision detection, I'm not into that field. You'll have to wait for someome else to jump in. Did you ask google for some general algorithms? It should not be too hard, to implement it in QML/JavaScript.
-
thanks volker,I will try it out.........
-
[quote author="imrrk" date="1294241393"]
can you provide me some fundamentals about this collision detection abt two bodies and also the bodies should respond to the collision.[/quote]this "fundamentals" are called Physics, so you'd better start with a couple of books on mechanics.
or just download Box2D qml plugin. it's kind of unfinished, and as far as I know only contains box object implementation, but you can look how it's done and implement other shapes yourself, it's not that complex
-
There are some ways to detect collision say for example to detect two rectangles getting collided
function isColiding (x1, y1, width1, height1,x2, y2, width2, height2) {
return (x1 < x2 + width2) && (y1 < y2 + height2) &&
(x1 + width1 > x2) && (y1 + height1 > y2);
}:)
-
Hi,
In the case of the example, one thing missing is that the collisiondetection function is not being called anywhere. A simple modification of the code might be to add a Timer object that calls this function every animation tick, something like:
@
Timer {
repeat: true
running: true
interval: 16
onTriggered: collisiondetection()
}
@
Regards,
Michael