I have an XYLineChart and I want to customize the shape of nodes into rings.
Like this:
Here is the code how I try to done this:
Ellipse2D bigCircle = new Ellipse2D.Double(-4, -4, 8, 8);
Ellipse2D smallCircle = new Ellipse2D.Double(-2,-2,4,4);
Area ring = new Area(bigCircle);
ring.subtract(new Area(smallCircle));
Shape ringShape = (Shape)ring;
renderer.setSeriesShape(0, ringShape);
But the result is like in the left image. It is like this renderer.setSeriesShape(0, bigCircle);
What I am doing wrong?
or
Exist a factory with shapes which include my shape?
My code is fine, but the problem is from line. How #samabcde said.
I made a bigger ring to see what exactly is.
Related
I have a 360° panorama picture (texture) that I map around a sphere and I place my camera inside the sphere to have a spherical projection. Now the texture is projected on the outside of the sphere.
I want to 'turn the texture inside-out' and i read it could be done by applying a matrix.
I'd like to apply a matrix to a sphere (Object3D) in Rajawali/OpenGL.
This can be done in ThreeJS like this:
var sphere = new THREE.SphereGeometry(100, 100, 40);
sphere.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));
three.js documentation for applyMatrix:
this updates the position, rotation and scale with the matrix.
and I'd like to do this in Rajawali:
mSphere = new Sphere(100, 100, 40);
//Apply the matrix here
Documentation for Matrix/Object3D can be found here
Matrix4
Object3D
Or is there any other way it could be done?
This has been fixed!
mSphere = new Sphere(100, 100, 40);
mSphere.setScaleX(-1);
mSphere.setScaleY(1);
mSphere.setScaleZ(1);
Isn't that really a job for material.side?
Quote from three.js doc for Material:
.side
Defines which of the face sides will be rendered - front, back or both.
Default is THREE.FrontSide. Other options are THREE.BackSide and THREE.DoubleSide.
So looking at a sphere surface from the inside should be using THREE.BackSide.
I would like to understand one thing , below I saw that a collision between two rectangles works .
create method:
//nave
spaceShip = new Image(new TextureRegion(new Texture(Gdx.files.internal("rocket.png")),98,154));
spaceShip.setOrigin(spaceShip.getWidth()/2, spaceShip.getHeight()/2);
spaceShip.setBounds(spaceShip.getX(),spaceShip.getY(),spaceShip.getWidth(),spaceShip.getHeight());
spaceShip.setZIndex(3);
//meteora
meteora = new Image(new TextureRegion(new Texture(Gdx.files.internal("planet.png")),128,128));
meteora.setOrigin(meteora.getWidth()/2,meteora.getHeight()/2);
meteora.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
meteora.setBounds(meteora.getX(),meteora.getY(),meteora.getWidth(),meteora.getHeight());
meteora.setZIndex(3);
Render method:
rect1 = new Rectangle(spaceShip.getX(),spaceShip.getY(),spaceShip.getWidth(),spaceShip.getHeight());
rect2 = new Rectangle(meteora.getX(),meteora.getY(),meteora.getWidth(),meteora.getHeight());
if(Intersector.overlaps(rect1,rect2)){
System.out.println("collision");
}
Now , my question is :
as I can see collisions with dynamic objects .
Let me explain, there will be different now created in a random time .
So how can I tell if a collision occurs with one of these objects and understand what it is .
Rectangle has no method .setName , I wanted to use this to figure out which object my ship touched .
Can anyone recommend a solution ?
Thank You
EDIT
add Image object
meteora = new Image(new TextureRegion(new Texture(Gdx.files.internal("planet.png")), 128, 128));
meteora.setOrigin(meteora.getWidth() / 2, meteora.getHeight() / 2);
meteora.setPosition(Gdx.graphics.getWidth() / 2, 100);
meteora.setZIndex(3);
Rectangle rect = new Rectangle(meteora.getX(),meteora.getY(),meteora.getWidth(),meteora.getHeight());
rectangles.add(rect);
I am not entirely sure what the question is, but in answer to what I think you are getting at:
Typically you would want to add all the new randomly created rectangles to a collection of rectangles, then you can iterate through this collection to check for collisions:
List<Rectangle> rectangles = new ArrayList<Rectangle>(); // a field in your class
// inside the method to create random rectangles
Rectangle tmp = new Rectangle(1,2,3,4);
rectangles.add(tmp);
// inside the method to check for collisions
for(Rectangle rect : rectangles) {
if(Intersector.overlaps(rect, shipRect) {
System.out.println("collision");
}
}
Note that your rect1 for your ship's bounds should be saved as a field (shipRect in this example) as well so that you can refer back to it at any time
So Im new to JME3 and I have a few problems understanding the BetterCharacterControl.
When I try to apply a BetterCharacterControl to a box it always "expands" from the upper part of the box instead of the center. (A picture explains that better:)
I cant find any functions to change the location it gets applied at, I already tried to create a subclass in which I changed the RigidBody to the BoxCollisionShape directly but that seems to somehow screw up the isOnGround Method. Also if I want to use slopes later it would be nice to have the capsule shape.
Box box2 = new Box(10, 15, 10);
player = new Geometry("Player", box2);
player.setLocalTranslation(new Vector3f(0, 20, 0));
Material mat = new Material(assetManager,
"Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", ColorRGBA.Blue);
mat.setColor("Diffuse", ColorRGBA.Blue);
player.setMaterial(mat);
playerC = new BetterCharacterControl(12, 30, 0);
playerC.setJumpForce(new Vector3f(0, 700, 0));
player.addControl(playerC);
rootNode.attachChild(player);
bulletAppState.getPhysicsSpace().add(playerC);
On a different note, it seems like I i have to apply a huge vector for the jump force for it to do anything (I didnt change any gravity values)
Im glad for any help
i had this same problem. The way I resolved it is not usual. I coded a class and did inherit from BetterCharacterControl overwriting getShape() method as follows:
protected CollisionShape getShape() {
//TODO: cleanup size mess..
CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius())));
CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape();
//Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0); REMOVED LINE
Vector3f addLocation = new Vector3f(0, 0, 0); //NEW LINE
compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation);
return compoundCollisionShape;
}
This works because the original code is a composite created in such a way so that the child node is offset by the value: (getFinalHeight () / 2.0f). The new line adds not realize this shift, leaving the object in the center position of the box set. However, this way of solving the problem, it can create problems when actually a composite mesh is used in the final object.
I am writing a simple game, or so it seemed. I created a class that draws a Arc2D (half a circle shape), that same class will repaint the arch as the mouse move.
Then I created a new class that draws ovals. This class has some simple mathematics to move the ovals on the screen. The movement of the ovals are not very important. So now that this is done I want to detect if the Oval collides with the arc(half a circle, Only the arc line) at any point.
What I have attempted is making the oval a Rectangle and use the intersect method. This code is in the draw method for the arc.
Arc2D temp= new Arc2D.Double(200, 200, 100, 100, angle, 180, Arc2D.OPEN);
MasterOval m = new MasterOval();
Rectangle r1 = m.bounds();//This gets the bounds of the oval
if(r1.intersects(temp.getBounds()))
System.out.println("hit");//display if intersects
For some reason I cant figure out why it will not display the word hit when it collides with the arc. Is there a way to see if they intercect? This is all code I can provide due to privacy policies. Please help.
Well, I'm not sure if your MasterOval class implements the Shape interface or not, but if it does (if it doesn't, consider using Ellipse2D.Double or something of that sort), the easiest way (standard perhaps ?) of checking for collision between Shape instances is using Area:
Shape1 shape1 = new Arc2D.Double(...);
Shape2 shape2 = new Ellipse2D.Double(...);
Area area1 = new Area(shape1);
Area area2 = new Area(shape2);
if (area1.intersect(area2)) {
...
}
Ok so I have a number of polygons (outlined in white in the image).
In an attempt to add all the polygons together so that I get one polygon, which is the outer bounds of all of them, I have converted each Polygon (java class) to an Area(java class) and then added the areas together with the add(Area a) method provided by the Area class.
From there I converted the area back to a polygon and drew it as a filled Polygon (the purple area in the image).
This however is not what I was expecting. Can anyone think of a was where I can do this correctly, or at least just add the triangle area to my polygon?
When I just draw all the separate polygons with a fill I get what I want (drawn) but I need a Polygon representation of it.
I can recommend to use JTS. Just create your geometries you want to combine and use the union method. Afterwards you can use the new geometry and paint it using your previous code. Simple code example for union:
// build polygon p1
Polygon p1 = new GeometryFactory().createPolygon(new Coordinate[]{new Coordinate(0,0), new Coordinate(0,10), new Coordinate(10,10), new Coordinate(10,0), new Coordinate(0,0)});
// build polygon p2
Polygon p2 = new GeometryFactory().createPolygon(new Coordinate[]{new Coordinate(0,0), new Coordinate(0,30), new Coordinate(5,30), new Coordinate(5,0), new Coordinate(0,0)});
// calculate polygon3 as the union of p1 and p2
Polygon p3 = (Polygon) p1.union(p2);
// print simple WKT
System.out.println(p3.toText());
Output in this case is (like expected):
POLYGON ((0 0, 0 10, 0 30, 5 30, 5 10, 10 10, 10 0, 5 0, 0 0))