I'm working on a game in Xamarin. I have a plane that I want to fly from one side of an arc to the other while rotating the plane so the plane stays parallel to the arc.
Any suggestions?
Update
I was able to get this to work using a combination of CCBezierTo and CCRotateTo.
As I mentioned in my update I was able to accomplish this by using a combination of CCBezier and CCRotateTo.
var duration = 5.0f;
mysprite.RunActionAsync(new CCBezierTo(duration, new CCBezierConfig()
{
ControlPoint1 = new CCPoint(180, 200),
ControlPoint2 = new CCPoint(650, 600),
EndPosition = new CCPoint(1130, 200)
}));
mysprite.RunActionAsync(new CCRotateTo(duration, 90));
The ControlPoint2 is the top of the arc.
Related
I was coding a simple shape-collision-detector, but I noticed the rectangle which I move using the mouse vanishes in some window's areas.
I can't figure out why.
Here you can see the video and below the code I used.
Any advice?
Rectangle r = new Rectangle();
r.setWidth(150);
r.setHeight(150);
Group root = new Group(r, e, boh);
Scene scene = new Scene(root, 1000, 1000);
scene.setOnMouseDragged(ev -> {
r.setX(ev.getX() - r.getWidth() / 2);
r.setY(ev.getY() - r.getHeight() / 2);
});
I solved by placing another Rectangle as background.
I am trying to animate a figure and adding a health bar over it. I created the figure from a sprite (new PIXI.sprite()) and the health bar from a graphics object (new PIXI.Graphics()).
I am able to move the sprite by setting its X,Y coordinates, but when I do the same with the Graphics object it is always displaced, it looks like its origin is the current position of the sprite. See the following picture. The health bar should be above the figure.
var app = new PIXI.Application(windowWidth, windowHeight, {backgroundColor: 0x1099bb});
var prey = new PIXI.Sprite(texturePath);
var healthBar = new PIXI.Graphics();
healthBar.beginFill(0x00BB00);
healthBar.lineStyle(1, 0x000000);
healthBar.drawRect(prey.x - spriteLength, prey.y - spriteLength, spriteLength, 5);
prey.energyBar = healthBar;
app.stage.addChild(prey);
app.stage.addChild(healthBar);
prey.energyBar.position.set(prey.x,prey.y);
How can I set the position of the health bar to be right above the figure?
A better way to do this would be to have the healthbar as a child of the prey Sprite itself. As an example (bits you've already solved missed out)
var prey = new PIXI.Sprite( texturePath );
var heathbar = new PIXI.Graphics();
healthbar.y = -100;
prey.addChild( healthbar );
app.stage.addChild( prey );
Now, that the health bar is a child of your prey Sprite, when you move the prey Sprite around, the healthbar will move with it (which I presume is what you would want in your situation).
Setting the initial coords of the health bar to (0,0) fixed the issue.
healthBar.drawRect(0, 0, spriteLength, 5);
I am trying to have the camera orbit around an arbitrary axis in world space. I've already spent so many hours trying to solve this issue without luck. I do not want to add a library like THREE.OrbitControls just to have this feature. Can anyone tell me what I'm doing wrong in the following code?
Camera.prototype.orbit = function(axis, spd, pt) {
var axis = axis.normalize(),
currCamQuaternion = new THREE.Quaternion(this.position.x, this.position.y, this.position.z, 0),
rotQuaternion = new THREE.Quaternion();
rotQuaternion.setFromAxisAngle(axis, spd);
var halfCamQuaternion = rotQuaternion.clone().multiply(currCamQuaternion),
fullCamQuaternion = halfCamQuaternion.clone().multiply(rotQuaternion.clone().conjugate());
this.position.copy(new THREE.Vector3(fullCamQuaternion.x, fullCamQuaternion.y, fullCamQuaternion.z));
this.lookAt(pt);
}
I have a simple rectangular wall and I like to place multiple window holes on it. It always works great for the first hole, but as soon as I add additional holes the polygon becomes messed up. See the images below to see what I'm talking about.
How can I draw holes properly in Three.js?
The right hole is not drawn properly.
After increasing the height of the right hole the entire wall mesh becomes halfcut.
Here is a sample code that causes above problem:
var shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(1, 0);
shape.lineTo(1, 1);
shape.lineTo(0, 1);
var windowHole = new THREE.Path();
windowHole.moveTo(0.14999999888241292, 0.7758620689655171)
windowHole.lineTo(0.4999999962747097, 0.7758620689655171)
windowHole.lineTo(0.4999999962747097, 0.3448275862068965)
windowHole.lineTo(0.14999999888241292, 0.3448275862068965)
shape.holes.push(windowHole);
windowHole = new THREE.Path();
windowHole.moveTo(0.5999999955296517, 0.7758620689655171)
windowHole.lineTo(0.7499999944120646, 0.7758620689655171)
windowHole.lineTo(0.7499999944120646, 0.6034482758620688)
windowHole.lineTo(0.5999999955296517, 0.6034482758620688)
shape.holes.push(windowHole);
var mesh = new THREE.Mesh(new THREE.ShapeGeometry(shape), this.material);
root.add(mesh);
The above code results in a warning:
Warning, unable to triangulate polygon!
at public_html/libs/three.js:27785
It turned out that this was a bug that is now fixed in version 66dev.
The bug was reported and discussed here:
https://github.com/mrdoob/three.js/issues/3386
The fixed version that I'm using now is developer built version 66dev committed at Jan 27th, 2014 here:
https://github.com/mrdoob/three.js/tree/dev/build
I assume this fix will be merged with the main three.js soon, but until then you can use the link above.
Some code might help. if possible link your code in jsfiddle...
just you need to change the order of the path creation... refer the link... http://jsfiddle.net/ebeit303/BuNb2/
var shape = new THREE.Shape();
shape.moveTo(-5, -5);
shape.lineTo(-5, 5);
shape.lineTo(5, 5);
shape.lineTo(5, -5);
shape.lineTo(-5, -5);
var windowHole = new THREE.Path();
windowHole.moveTo(-2,-2);
windowHole.lineTo(0,-2);
windowHole.lineTo(0,0);
windowHole.lineTo(-2,0);
windowHole.lineTo(-2,-2);
shape.holes.push(windowHole);
windowHole1 = new THREE.Path();
windowHole1.moveTo(3,3);
windowHole1.lineTo(4,3);
windowHole1.lineTo(4,4);
windowHole1.lineTo(3,4);
windowHole1.lineTo(3,3);
shape.holes.push(windowHole1);
var geometry = new THREE.ShapeGeometry( shape );
var material = new THREE.MeshBasicMaterial({color:0xffccff, side:2, overdraw:true} );
var mesh = new THREE.Mesh(geometry, material );
group.add(mesh);
Have a look on http://learningthreejs.com/data/constructive-solid-geometry-with-csg-js/. Whatever your codes are it will help you in doing it better. Substraction, addition, union, intersection everything is possible.
i want to show a mesh (like gunshot) in front of my perspective camera(with first person controls) i wrote this code in the render function of my page:
var pos = camera.position;
var rot = camera.rotation;
shot.rotation.x = rot.x;
shot.rotation.y = rot.y;
shot.rotation.z = rot.z;
shot.position.x = pos.x;
shot.position.y= pos.y;
shot.position.z = pos.z + 500;
if i just change the position of my camera its good, but if i change the camera's rotation i don't see the shot in front of that.
how can i do this?
It would seem that you need to make the "shot" a child of the camera. It's not clear from your example whether you're doing that already, but this should make the shot move around with the camera properly.