"Glueing together" two bodies in cannon.js - cannon.js

This must be really simple, but I can't seem to get, how one could fix together two bodies in cannon.js. I have experimented with different types of constraints no (first I thought, LockConstraint should be exactly what I need, being desribend as "removing all degrees of freedom").
What I want to achieve is to "stick together" several bodies so that they rotate/behave together if one of them moves/rotates, e.g. like a hammer to its shaft, but absolutely "fix". (The constraints behave a little like if the bodies were connected with rubber bands, even if applying a very high "maxForce" option)
How would I do that? Is body.addShape() the right direction..?!
Thanks a lot for any hints.

If you want two shapes to always have the same relative transform, you should put them in the same Body.
This example code creates a body with two boxes in it, at X=2 and X=-2 locally in the Body, relative to the center of mass.
var body = new CANNON.Body({ mass: 1 });
var shapeA = new CANNON.Box(new CANNON.Vec3(1,1,1));
body.addShape(shapeA, new CANNON.Vec3(2,0,0), new CANNON.Quaternion());
var shapeB = new CANNON.Box(new CANNON.Vec3(1,1,1));
body.addShape(shapeB, new CANNON.Vec3(-2,0,0), new CANNON.Quaternion());
Also see the compound demo: http://schteppe.github.io/cannon.js/demos/compound.html

Related

Overlap PNG taken from another part of PNG in unity3d

I'm surfing lot in google and spending more time but couldn't find the solution.
I tried converting PNG to bytes[] then attaching but no solution I found.
I have two PNG file one is full of Props like Hair, Dresses, Hand Glow, etc,.. another is undressed character. How to implement to show Glow, Hair and Dressed up Character. Simply I planned to Drag and Drop, Drag the hair and drop on head of the character to show.
How could I merge part of PNG[Hair, Glow, Dress..] file and drop on another Part of PNG[Head. Hand, Body...] file.
Shall I split different PNG files like Hair part alone, Glow part alone, Dress part alone.
Which is best way to do this Please give some link or project for reference or give some idea theoretically
NOTE: This only in 2D[PNG images] not 3D characters or materials.
Please refer this image
You don't want to merge them, you want to make them overlap.
public class CharacterSprite:MonoBehaviour{
public Vector2 position;
public Item itemValue;
}
public enum Item{ None, Hat, Eyes, Mouth,...}
Your character would have a ItemController:
public class ItemController:MonoBehaviour
{
private CharacterSprite hat
public void SetItem(CharacterSprite shSp){
switch(shSp.itemValue){
case Item.Hat:
this.hat.gameObject.SetActive(false);
this.shSp.gameObject.SetActive(true);
this.hat = shSp;
break;
// other cases
}
}
}
This method would swap the current off and put the new one on.
But the layer on the SpriteRenderer is the important one there as you would expect the body to be 0, hair is 1 maybe eyes over the hair so 2 then the clothes and hats are 3 (maybe eyebrows are over hats, dunno), weapons should be seen over it all so 10 (this gives some leeway for other items in between).
I would consider this approach faster, safer and saving memory since you are keeping your sprites are they are and you are only overlapping them.
You can easily make unique sprites from your atlas using the SpriteEditor. You just need to make your sprite as multiple.

create multiple sprites(nodes) with same texture swift

So i'm trying to make a game and i have to generate a row of nodes that accelerates upward. But every time if I add the node I get an error (because the node already has a parent) obviously I added Sprite.removeFromParent()
in the image you can kind of see what I'm trying to implement.
Anyway the blocks also have to register how many times they're touched.
To answer the question that is in the title:
Pretty simple, create an SKTexture and for each SKSpriteNode set the texture to that SKTexture. The code for that would look something like this:
// Create the texture
var boxTexture = SKTexture(imageNamed: "boxImage")
for (var i = 0; i < 10; i++) {
// Create box with defined texture
var box = SKSpriteNode(texture: boxTexture);
// Set position of box dynamically
box.position = CGPointMake(CGFloat(i * 20), CGFloat(512));
// Name for easier use (may need to change if you have multiple rows generated)
box.name = "box"+String(i);
// Add box to scene
addChild(box);
}
The problem that you are having in your description appears to be that you are only creating one SKSpriteNode when you need multiple to go across the bottom. Simply use a for loop to create multiple, and add them all to the scene (basically, the same code from above). You may wish to give them all name properties in order to figure out which box is which later on (if you don't store them as global variables). Make sure to change around the naming if you have multiple rows of boxes moving at the same time.

GWT-OpenLayers: Highlighting points with different styles on a layer

I have several points on a layer and all might have different styles associated with them. So I'm doing
VectorFeature pointFeature = new VectorFeature(point,pointStyle)
It all works fine until I do the select(i.e. click the point). When I do a select, the points are not highlighting. The point highlighlights if I remove the pointStyle from the VectorFeature, i.e.,
VectorFeature pointFeature = new VectorFeature(point)
I tried using StyleMap on the layer but ended up getting the same result.
What could possibly be the solution to this problem?

add shape dynamically to activereports

I've got a kinda requirement in which there is a kinda graph (static picture) on a page. In that picture I need to plot some points dynamically. That means using a shape filled with blue color. The number of points is floating depending upon the number of applicants choosen. How can I make it work or how can I add new elements to report at runtime. Am working in ASP.nET using VB and the AR version is 6.2
If I have understood your query right,then you want to plot some points depending on the dynamic data.
A suggestion would be to make use of Chart control in report. The chart can be bound to anything from a list to an array and the data can be changed dynamically from time to time.
Moreover,you can set the backcolor and other properties of the Chart control to give a look and feel of your choice.
Regards,
Mohita
Sorry if my question makes any confusion.. Actually I was able to make that. So am just sharing that code if it helpful for someone else.. I put this to the report start event. (We are not permitted to make this in details event)
Dim pic As New DataDynamics.ActiveReports.Picture
pic.Image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(String.Format("~/images/circle.gif", cl)))
pic.SizeMode = SizeModes.Zoom
Detail1.Controls.Add(pic)

Click-through markers and polylines in Leaflet

In Leaflet, is it possible to define a marker or polyline with {clickable:false}, so that a click is passed through to whatever lies beneath - be it the map or a clickable geometry object?
At the moment I solve this problem by making the marker/polyline clickable and passing the event onwards myself. But this leads to the mouse cursor always showing as the hand symbol. Ideally, the mouse cursor should look like the normal pointer or the hand, depending on whether what is beneath the marker/polyline is clickable.
This may not be the answer you are looking for, but you can use featureGroups to have all of your clickable polylines come to the front so that the actions are surfaced.
var lg_noclick = new L.FeatureGroup().addTo(map);
var lg_click = new L.FeatureGroup().addTo(map);
// Add lines
lg_click.bringToFront();
updated fiddle
Also if you can afford to know your lines before hand, correct ordering of when you add the lines it will work as well.
I know this is not ideal but it suited my situation just fine, so it might be good for you as well.
This hides the icon and brings it back after a second using mouseenter and mouseleave events:
$('.leaflet-marker-icon').mouseenter(function() {
$(this).hide();
});
$('.leaflet-marker-icon').mouseleave(function() {
$(this).delay(1000).show(0);
});