Calculate Protractor Angle in WP7 - windows-phone-7

I am trying to create a protractor in windows phone 7 using silverlight framework and I am stuck in getting the protractor needle to rotate.
I am using rotate transform and specifying the angle value to the transform name in the code behind.
I need a perfect angle calculation and currently the protractor needle is not rotating as required.
Any help would be truly appreciated, thanks.

try this:
var rotateTransform = (RotateTransform)yourControl.RenderTransform;
rotateTransform.Angle = 90.0f;
I wrote this out of top of my head, but this is general rule how you should do this in code behind... the other thing is - make sure you are getting some values via Debug.WriteLine() and then watch Output in VS.

Related

PIXI js - Pixel Data is Zero

I'm currently working on a little game written in JS using Pixi.js(https://github.com/pixijs). One Problem has occured currently, I'm trying to implement pixel exact collision between shapes, while I was programing a little I noticed that all the pixel RBGA values of my images are just 0.
I searched on the web but for a while but the only reason for those Problems I could find was that the canvas was tainted because of CORS(Pixel RGB values are all zero).
But this can't be the reason in my case because I created the sprites myself, I'm not loading them from other (any) domains or something like that.
Could this be a problem with the images? How do I avoid that? I will append some code that works if I use other images (some images I downloaded for tests).
const app = new PIXI.Application({width: 500, height: 500});
document.body.appendChild(app.view);
PIXI.loader.add("sprites/test.png")
.load(() => {
let img = new PIXI.Sprite(PIXI.loader.resources["sprites/test.png"].texture);
app.stage.addChild(img);
console.log(app.renderer.extract.pixels(img));
});
Edit: I tried getting the RGBA values using a short Java Program btw, same problem. Every single value is zero.

How to make a "Springy curve" in Flutter for a button scale effect?

I'm trying to make a pleasing "spring" effect to scale a button and other components. In particular I want to scale them in when the view is created and shown, and I want to scale them down when a user taps a button, and if the user releases the button, I want them to scale back up to normal size with the spring effect.
The Facebook library "rebound" is a perfect example, see their demo here: https://facebook.github.io/rebound/.
I tried all the built in curves like bounceIn/Out and elasticIn/Out but they weren't springy enough (elastic is kind of springy).
Any help greatly appreciated!
As #Remi said, you can use the Curve class and override the transform method.
The difficult part is then figuring out the formula to use. I'd play around with something like this curve calculator to get a formula.
i.e. -(e^(-x/a) * cos(xw)) + 1 with a = 0.15 and w = 19.4.
Another alternative is to use existing curves together - since they all start at 0 and end at 1, you can simply multiply two different curves together in your overloaded curve method.
I'd take a look at the implementation of ElasticIn and ElasticOut to figure out how they did the math, but the dart math library should have everything you need.
You can create your own Curve by overriding transform.
As long a mycurve.transform(0) == 0 and mycurve.transform(1) == 1 you can do pretty much anything.
Better late than never:
you may find the package https://pub.dev/packages/sprung useful.

use applyTorque() in deg/sec² - Box2D

I am trying to figure out how to use correctly body.applytorque(float torque, boolean wake) method on a body with a center of mass, to accelerate it's angular velocity. I want to apply an angular acceleration, in degrees per square second.
According to the libGDX doc, torque parameter uses Newton-meters. To set it, i'll use the formula :
𝛕 = I α
where 𝛕:torque[N-m], I:mass moment of inertia, α:acceleration
on the body :
// java
float acceleration = 120f; // deg/s²
float inertia = body.getInertia();
body.applyTorque(inertia * (float)Math.toRadians(acceleration), true);
but this leads to wrong acceleration, same thing with the mass.
What is the proper use of that method, in deg/s²?
Resolution : the problem came from the world editor UI i was using -
Overlap2D.
How to correct : multiply the torque by 2 in applytorque(...) .
The method i mentionned was used correctly in my example above, and so was the formula.
With Overlap2D software, I'm able to place all the bodies i want into a scene. When I then load the bodies and assets in my program, i load directly the world with. I use some convenience classes provided by ashley, e.g IteratingSystem, to compute directly every entity's behaviour at each rendering. This processing is affecting the forces, or at least torques. However i had no problems with angular impulses.
Thank to David Jeske and Louis Langholtz for having guided me.

Smooth animation of three shapes in SciLab

This answer provides a nice way to make smooth animations in SciLab. I now have to write a simulation of a body attached to two strings (and therefore its movement regarding some additional forces).
The code in the link works well to render movement of a single point and, unfortunately, I didn't manage to make an animation of a point + two lines using this method. If someone is curious, I tried this code to do it:
frametime=(tk-t0)/Nt//defining the waitnig time
plot(Y(1,1),Y(2,1),"o")//plotting the point
plot([0;Y(1,1)],[0;Y(2,1)],style=1)
plot([D;Y(1,1)],[0;Y(2,1)],style=1)//plotting the two initial lines
h1_compound = gce();
h_point=h1_compound.children
h_point.mark_size = 20;
h_point.mark_background = 2;
h_line1=h_compound.children
h_line2=h_compound.children
//h_axes = gca();
//h_axes.data_bounds = [0,-1;10,1];
realtimeinit(frametime);
for i=1:Nt//my vectors have Nt points
realtime(i);//wait "frametime" seconds before drawing the new position
h_point.data=[Y(1,i),Y(2,i)];
h_line1.data=[[0;Y(1,i)],[0;Y(2,i)]]
h_line2.data=[[D;Y(1,i)],[0;Y(2,i)]]
end
The question is: is there any way to make an animation of three shapes without making axes blink (as it is with the window refreshment) or other wierd stuff?
Since you didn't create a MCVE I can't reproduce your exact problem. But you may try to add drawlater(); before, and drawnow(); after your data modification to see if it does help with blinking or not.
Or you may get much better looking result by saving your plots in every round with xs2gif and assemble the animation with another gifmaker progam (there are free online sites to do this, however with some limitations). If you need to present your result, you should do this step anyway.

Animation with dynamic parameter - Unity3d

I have an object - just cylinder (looks like chip) and I want to add to this object like Flip animation. When chip is flip - chip will go up and rotate in the air. Now I want to give a dynamic parameter determines Height for go up.
So right now I know 2 ways:
1) Is just in c# code write object.Rotate() with parameters
2) Write animation clip - and call in C# for Play - but here -I can't pass parameters (right or not?)
So please guys - just give me direction (links) for good Get started with unity3d. Sorry for my English - it's very bad I know ((
The best way to do it purely by script is definitely by using tweeners, I would suggest using this tool : https://www.assetstore.unity3d.com/en/#!/content/27676
Now after downloading this asset to your Unity just create a new script and include the asset
using DG.Tweening;
And here is simple method for doing the actual jump with dynamic parameters.
public Transform chip;
void JumpWithRotation(float heightOfJump, float timeForJump){
DOTween.Init(false, true, LogBehaviour.ErrorsOnly);
chip.DORotate (new Vector3 (0, 180f, 0), timeForJump).SetEase (Ease.InOutSine);
chip.DOMove (new Vector3 (0, heightOfJump, 0), timeForJump).SetEase (Ease.InOutSine);
}
The best thing about tweeners is that you can easily implement easing methods (making transition between two values (linear, sine, exponentional...)).
You can pass parameters to Animation - because animation is just file(it's not a code). So sure - if you want to pass dynamic parameters - you have only one options - by scripts. Just write 1 method who take GameObject and parameters for rotation and its done! good luck

Resources