I wonder how could I get the correct palm rotation angle (along Y-axis) from Leap Motion (I'm using the latest LeapJS API)?
I have tried both rotationAngle(sinceFrame) method and the frame._rotation. However, the rotationAngle() returns a very small value close to 0, which seems to be the rotation angle calculated based on the current frame (how to define the sinceFrame in Leap.loop(function(frame)){}, as it seems only records data from current frame).
And the frame._rotation returns a 3*3 matrix (which I've no idea about what is it, as it's not included in the API documentation). Therefore, I wonder if there's any way to get the correct rotation angle of Y-axis from these methods?
The latest version of the leap.js library includes a roll() function as a member of the Hand object. (It also has pitch() and yaw(), if roll() isn't all you want.) The roll() function is defined as:
Hand.prototype.roll = function() {
return Math.atan2(this.palmNormal[0], -this.palmNormal[1]);
}
As an aside, since you don't need to use rotationAngle() to get the current palm angles, the rotationAngle() function gives you the rotation that has occurred between two frames. For sinceFrame, you can either store a reference to the starting frame or get a past frame from the history buffer maintained by the Controller object. Although the Leap.loop() function doesn't give you access to its Controller object directly, you should be able to create your own. Note that frame._rotation is an internal variable that is used in the calculation of the transformations between two frames. It isn't much use on its own.
Related
How to use pymunk.Body.update_velocity(body, gravity, damping, dt) to dampen the mass. I know I can use global damping here but I want to add more masses later on and have custom damping for each one, and so I want to learn how to deploy body-specific damping. I have the following questions
How to use pymunk.Body.update_velocity
Can I leave gravity blank if I don't want custom gravity. Or should I just write space.gravity
What is dt here and how do I determine that
Did you find the example in the documentation here: http://www.pymunk.org/en/latest/pymunk.html#pymunk.Body.velocity_func ?
You need to define a custom velocity function somewhere, and then set it on the body you want it. So preferably you define it before you create the bodies. In this function you can call the existing default velocity function (pymunk.Body.update_velocity) if you want, but that is not a requirement. It depends on if you want to write all code to update velocity of the body yourself, or if you want to just modify it a bit with the existing code as a base. Since you only want to modify the damping I think its easiest to call the default function.
When you call the default v function you can send in the same gravity unmodified as you get it in your custom function.
dt is the delta time. I see now the docs could be improved here, I will make a note. So the dt is the same value as the dt sent to space.step(dt) function in your simulation loop.
All in all, I think something like this would do (you just need to adjust the calculation of modified_damping to the logic you want):
def custom_damping(body, gravity, damping, dt):
modified_damping = body.custom_damping * damping
pymunk.Body.update_velocity(body, gravity, modified_damping, dt)
body.custom_damping = 0.31415
body.velocity_func = custom_damping
(if you dont want to set a variable on the body you can of course do it in some other way. Lets say you want all bodies to have 2x the damping compared to normal you could do modified_damping = 2 * damping instead, and remove the body.custom_damping property.
I am upgrading from Bing Maps V7 to V8 and rotating the map from JS doesn't work anymore. I have been trying with this piece of code:
map.setView( { heading:90 } );
This works if I change the source URL for the map library to V7. And I see that the "setView" function and the "heading" option still exist in V8.
Here's an article about how to do it in V7:
https://alastaira.wordpress.com/2012/03/28/rotating-bing-maps/
Bing Maps V8 currently doesn't have Birdseye. A new birdseye experience is being introduced to V8 within the next few months. This new experience has a lot of new imagery which uses a different format from the old birdseye experience. Given that the imagery that is in V7 is very old and is a major point of DSAT, it was decided to hold off on adding birdseye to V8 until the next experience and data is available.
I did some more research and two undocumented things have changed.
map.setView() does not respond to a full options object anymore.
Example:
var options = this.map.getOptions();
options.heading = 90;
map.setView(options);
It now needs the heading and other changed fields manually specified to reflect any changes.
map.setView({heading: 90});
map.setView({heading: xx}) no longer accepts negative values as valid so you must manually submit heading values for any clockwise rotations so that it corresponds to the positive heading value.
Thus, map.setView({heading: -90}) was previously smart enough to know that is equivalent to map.setView({heading: 270}), but now must be submitted to the API as a positive value.
Similar to the first example, I have some legacy code for resetting the map back to original lat/lon and heading that now needs a second setView() call in order to update.
var options = this.map.getOptions();
options.zoom = this.initialZoom;
options.center = new Microsoft.Maps.Location(this.lat, this.lon);
options.heading = this.heading = 0;
this.map.setView(options);
this.map.setView({heading: this.heading});
Must call setView another time so that the new heading is actually applied.
This is my code for the enemies in my game
//Collision
if (place_meeting(x,y,Object_Wall))
{
speed = 0
direction = point_direction(x,y,Object_Wall.x,Object_Wall.y) + random_range(160,200)
speed = sp / 2
time = random_range(room_speed * 0.75,room_speed * 3)
}
When the zombie hits a wall, it should turn back and walk the other way.
This works most of the time but sometimes they will just drift through walls and if they are following the player and he goes next to a wall they go through it.
I don't know why it doesn't work sometimes and would like help to fix this.
I am using Object_Wallas a parent object and they work with it but the problem occurs with it's children.
When you use point_direction(x,y,Object_Wall.x,Object_Wall.y), it's not object which was found using place_meeting(x,y,Object_Wall).
place_meeting(x,y,Object_Wall) will check collsion with all instances of object Object_Wall. But when you use in point_direction object id instead instance id, GM will take first (in creation order) instance of object Object_Wall.
You can take instance id using, for example, collision_circle function.
But I recommend use Collision event and other keyword inside it.
I was trying to get which vertex of a Feature has been modified. It seems that featuremodified event does not supply this information.
this is important because I will have to post the modification to the server. I dont want to post the whole feature object because of one single vertex change.
I am using OpenLayers v2.13.1
You need to hook into the vertexmodified callback of OpenLayers.Layer.Vector. This is triggered by the dragVertex function of OpenLayers.Control.ModifyFeature, see line 479 here http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
The vertexmodified function receives a vertex, a feature and a pixel, so you would write something like this, assuming an OpenLayers.Layer.Vector called vector:
vector.events.register('vertexmodified', this, function(vertex, feature, pixel){
//do something with the vertex
});
I'd like to ask re: measurement conversion on the fly, here's the detail :
Requirement: To display unit measurement with consider setting.
Concerns:
- Only basic (neutral) unit measurement is going to be stored in database, and it is decided one time.
The grid control has direct binding to our business object therefore it has complexity to do conversion value.
Problem:
How to display different unit measurement (follow a setting), consider that controls are bind to business object?
Your kind assistance will be appreciated. Thank you
ikadewi
If I've understood your question correctly (you are a little vague...) you want to store measurement data in one way, but give the users the option to display it in different ways (using different units). You don't specify which technology/language environment you're using, but there is (at least) one pretty straightforward way to do this: create a converter class.
Here's some pseudo-C# skeleton code if your measurement data is lengths, stored in millimeters. You can probably figure out how to use the same approach for whatever you're measuring, and however you want to display it:
class LenghtConverter {
double ToCentimeters(double millimeters) {
// 1 centimeter = 10 millimeters
return millimeters / 10;
}
double ToInches(double millimeters) {
// 1 inch = 25.4 millimeters
return millimeters / 25.4
}
// You get the drift. Add whatever conversions you need. If you wish,
// you can return strings instead of numbers, and append the unit
// signature as well.
}
Now, in your grid you display your data with some kind of presentation syntax. I'm making something up to give you an idea, and since I'm into ASP.NET the syntax is pretty similar to that. Hope you'll excuse me for that =)
Instead of just
<%= MyMeasurement.Data %>
to display the measurement data in the way it was stored, you output with
<%= LenghtConverter.ToInches(MyMeasurement.Data) %>
which will display the result in inches.
If you're actually using C# (or VB.NET, I suppose) there is a nice feature available in .NET 3.5 called Extension Methods that you might want to use instead. That would let you output with the somewhat cooler and more streamlined syntax
<%= MyMeasurement.Data.ToInches() %>
I have a QML Qt C++ UI. It interfaces with a back-end application.
UI supports both Imperial & Metric modes. User can make this selection from UI at runtime.
User can view and edit data values via the UI.
Back-end application works only in Imperial mode.
A C++ utility object is exposed to QML as a context property. This utility object has methods to:
Set and Get the System of measurement.
Convert unit string from Imperial to Metric. Example: °F to °C.
Convert data value from Imperial to Metric and Metric to Imperial. Example: Fahrenheit to Celsius -> 50 to 10, Celsius to Fahrenheit -> 0 to 32.
C++ data object has these 2 properties:
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QString unitString READ unitString NOTIFY unitStringChanged)
// value - In Imperial mode, you get Imperial value. In Metric mode, you get Metric value.
// unitString - In Imperial mode, you get Imperial units. In Metric mode, you get Metric units.
QVariant data::value()
{
// fetch Imperial data value from back-end application
// get current System of measurement
// if current System of measurement is Metric, convert data value from Imperial to Metric
// return data value
}
QString data::unitString()
{
// fetch Imperial unit from back-end application
// get current System of measurement
// if current System of measurement is Metric, convert unit from Imperial to Metric
// return unit
}
void data::setValue(QVariant value)
{
// get current System of measurement
// if current System of measurement is Metric, convert value from Metric to Imperial
// write value to back-end Controller application
}