CarChallenge 3D Demo
import QtQuick 2.0
import Felgo 3.0
import Qt3D.Core 2.0
import Qt3D.Render 2.0
EntityBase {
id: entity
entityType: "rocket"
Component.onCompleted: {
console.debug("Rocket.onCompleted, width:", width);
applyForwardImpulse();
}
BoxCollider {
id: boxCollider
width: 50
height: 20
anchors.centerIn: parent
density: 0.003
friction: 0.4
restitution: 0.5
body.bullet: true
body.fixedRotation: true
property var lastWall: null
fixture.onBeginContact: {
var fixture = other;
var body = other.getBody();
var otherEntity = body.target
var collidingType = otherEntity.entityType
if(collidingType === "car" ||
collidingType === "rocket") {
entity.removeEntity()
return
}
if(otherEntity === lastWall) {
return;
}
lastWall = otherEntity
var normalAngle = 180 / Math.PI * Math.atan2(contactNormal.y, contactNormal.x)
var angleDiff = normalAngle - entity.rotation
var newAngle = entity.rotation + 2 * angleDiff + 180
entity.rotation = newAngle
boxCollider.body.linearVelocity = Qt.point(0,0)
applyForwardImpulse();
}
}
Image {
id: image
source: "../../assets/img/rocket_green.png"
anchors.centerIn: parent
width: boxCollider.width
height: boxCollider.height
}
Render3D {
id: render
source: "../../assets/3d/rocket.obj"
texture: "../../assets/3d/rocket_col.jpg"
rotation: parent.rotation + 90
rotationAxis: Qt.vector3d(0,0,1)
yOffset: -10*scaleOffset
scaleOffset: 2
zOffset: -10
}
Render3D {
zOffset: -0.2
rotation: parent.rotation + 270
rotationAxis: Qt.vector3d(0,0,1)
rotationOffset: 270
rotationAxisOffset: Qt.vector3d(1,0,0)
texture: "../../assets/3d/rocket_shadow.jpg"
components: [renderTransform, material, planeMesh]
}
PlaneMesh {
id: planeMesh
width: boxCollider.height * 2
height: boxCollider.width
}
function applyForwardImpulse() {
var power = 1500
var rad = entity.rotation / 180 * Math.PI
var localForward = Qt.point(power * Math.cos(rad), power * Math.sin(rad))