SCNPhysicsHingeJoint not rotating if shape is complex - ios8

I'd found a strange behaviour in joint rotation of collada object in SceneKit.
Imagine, I use this code for make rotating desk (complex form desk made in cheeta3d):
SCNScene *heroScene = [SCNScene sceneNamed:#"scene.dae"];
b = [heroScene.rootNode childNodeWithName:#"desk" recursively:YES];
b.physicsBody = [SCNPhysicsBody dynamicBody];
b.physicsBody.physicsShape=[SCNPhysicsShape shapeWithNode:b options:#{SCNPhysicsShapeTypeKey:SCNPhysicsShapeTypeConcavePolyhedron,SCNPhysicsShapeKeepAsCompoundKey:#YES}]; //**HERE we need YES only, if NO it is not rotating**!
[scene.rootNode addChildNode:b];
SCNPhysicsHingeJoint *joint = [SCNPhysicsHingeJoint jointWithBody:b.physicsBody axis:SCNVector3Make(0,1,0) anchor:SCNVector3Make(0,5,0)];
[scene.physicsWorld addBehavior:joint];
Look at comment //HERE we need YES only, if NO it is not rotating!
I tested all cases, all joints. SCNPhysicsShapeKeepAsCompoundKey must be YES although I think it is not so important here.
Why is it?

SCNPhysicsShapeKeepAsCompoundKey defaults to YES. From what I can tell that turns off the " flattenedCone " version of the physics object. Most likely you have something in your model that is keeping it from rotating when the hinge joint attaches to only one section of the model instead of the whole thing.

Related

GameMaker studio 2. Player Knockback

trying to create a player damage indication when a collision with an enemy occurs.
I used this code within a collision event of the player object:
direction = point_direction(other.x,other.y,x,y);
hsp = lengthdir_x(6,direction);
vsp = lengthdir_y(4,direction)-2;
if (sign(hsp) !=0) image_xscale = sign(hsp);
However, the player object is simply pushed upward vertically rather than backwards in a parabola.
Any, ideas on how to implement a basic knockback system?
If you want a parabola, you can add an upward force afterward, like so:
direction = point_direction(other.x, other.y, x , y);
speed = 6
motion_add(90, 3)
If you don't and you'd rather a more "repeatable" parabola that always look the same, maybe you should use another method, something like
if other.x>x {hdirection=1}else{hdirection=-1}
hspeed = hdirection*6
vspeed = -2
I believe this would work better for what you're trying to achieve, unless you want to implement knockback variable depending on the angle of collision.
So I would need to see all the rest of your player physics to be sure, but I can tell you right now that direction = point_direction(other.x,other.y,x,y); is probable not what you mean, and same goes for lengthdir(). The exact origins of the colliding objects at the moment of collision have a huge effect on what that direction is, which can cause a lot of screwiness. For example: if the line is perfectly horizontal (because other.y == y) then lengthdir_y() will always be equal to zero for any input value no matter how huge.
But more importantly direction is a built-in variable of GameMaker, so using it with a custom physics system can also cause some screwiness. Fox's answer might help if you are using built-ins, but based on the fact that you have an "hsp" and "vsp" instead of hspeed and vspeed, my guess is you want to avoid built-ins.
If you just want to get the horizontal direction of the collision, you should use sign(x - other.x). Then, instead of using lengthdir(), you can just use a constant. Here it is all together:
var dir = sign(x - other.x)
hsp = 6*dir; //I'm assuming that 6 is how much horizontal you wanted
vsp = -4;
if (sign(hsp) !=0) image_xscale = sign(hsp); //This line could just go in your step event
Hope that helps! Feel free to comment if you have more questions.

Save a figure to file with specific resolution

In an old version of my code, I used to do a hardcopy() with a given resolution, ie:
frame = hardcopy(figHandle, ['-d' renderer], ['-r' num2str(round(pixelsperinch))]);
For reference, hardcopy saves a figure window to file.
Then I would typically perform:
ZZ = rgb2gray(frame) < 255/2;
se = strel('disk',diskSize);
ZZ2 = imdilate(ZZ,se); %perform dilation.
Surface = bwarea(ZZ2); %get estimated surface (in pixels)
This worked until I switched to Matlab 2017, in which the hardcopy() function is deprecated and we are left with the print() function instead.
I am unable to extract the data from figure handler at a specific resolution using print. I've tried many things, including:
frame = print(figHandle, '-opengl', strcat('-r',num2str(round(pixelsperinch))));
But it doesn't work. How can I overcome this?
EDIT
I don't want to 'save' nor create a figure file, my aim is to extract the data from the figure in order to mesure a surface after a dilation process. I just want to keep this information and since 'im processing a LOT of different trajectories (total is approx. 1e7 trajectories), i don't want to save each file to disk (this is costly, time execution speaking). I'm running this code on a remote server (without a graphic card).
The issue I'm struggling with is: "One or more output arguments not assigned during call to "varargout"."
getframe() does not allow for setting a specific resolution (it uses current resolution instead as far as I know)
EDIT2
Ok, figured out how to do, you need to pass the '-RGBImage' argument like this:
frame = print(figHandle, ['-' renderer], ['-r' num2str(round(pixelsperinch))], '-RGBImage');
it also accept custom resolution and renderer as specified in the documentation.
I think you must specify formattype too (-dtiff in my case). I've tried this in Matlab 2016b with no problem:
print(figHandle,'-dtiff', '-opengl', '-r600', 'nameofmyfig');
EDIT:
If you need the CData just find the handle of the corresponding axes and get its CData
f = findobj('Tag','mytag')
Then depending on your matlab version use:
mycdata = get(f,'CData');
or directly
mycdta = f.CData;
EDIT 2:
You can set the tag of your image programatically and then do what I said previously:
a = imshow('peppers.png');
set(a,'Tag','mytag');

Ruby SketchUp ... add a measurment

still learning about Ruby + Sketchup!
Today,I would like to add a measurement (good english word ?) as I can do manually with the 'cotation' (french version) tool when I click to point then drag the measure text.
Can't find that in the docs to do with Ruby and API ...
Thanks for your help
You are probably looking for the Sketchup::Entities::add_dimension_linear method.
http://ruby.sketchup.com/Sketchup/Entities.html#add_dimension_linear-instance_method
Assuming a and b below are edges
voffset = [-20, 0, 0]
Sketchup.active_model.entities.add_dimension_linear(a.start, b.start, voffset)
The value of voffset controls not just how far offset the dimension is, but also the axis along which the measurement is made. You may need to experiment with different values to get a feeling for how that determination is done. As with many things in SketchUp, it often guesses (or 'infers') at what you want.

Paraview rotate fields

I am using Paraview 5.0.1. If any solution requires updating, I can try.
I want to programmatically obtain field plots (and corresponding PlotOverLine) of displacements and stresses in rotated coordinate systems.
What are appropriate/convenient/possible ways of doing this?
So far, I have created one Calculator filter for each component of displacements and stresses.
For instance, I used Calculators in 2D with results
(displacement.iHat)*cos(0.7853981625)+(displacement.jHat)*sin(0.7853981625)
(stress_3-stress_0)*sin(45.0*3.14159265/180)*cos(45.0*3.14159265/180)+stress_1*((cos(45.0*3.14159265/180))^2-(sin(45.0*3.14159265/180))^2)
It works fine, but it is quite cumbersome, in several aspects:
Creating them (one filter per component).
Plotting several of them in a single XY plot
Exporting them (one export per component).
Is there a simple way to do this?
PS: The Transform filter does not accomplish this. It rotates the view, not the fields.
Two solutions:
Ugly, inneficient solution
Use Transform and check "Transform All Input vectors"
Add a calculator and add a dummy array
Use transform the other way around, without checking "Transform All Input vectors"
Correct solution :
Compute the transformation yourself in a programmable filter
input = self.GetUnstructuredGridInput();
output = self.GetUnstructuredGridOutput();
output.ShallowCopy(input)
data = input.GetPointData().GetArray("YourArray")
vec = vtk.vtkDoubleArray();
vec.SetNumberOfComponents(3);
vec.SetName("TransformedVectors");
numPoints = input.GetNumberOfPoints()
for i in xrange(0, numPoints):
tuple = data.GetTuple(i)
transform(tuple) # implement the transform in python
vec.InsertNextTuple(tuple)
output.GetPointData().AddArray(vec)

THREE.js Migration r60 to r70: now cannot write: mesh.position = myVector3()

I am migrating a THREE.js app from r60 to r70. Amongst other changes I notice that r60 constructs of the following form no longer work in r70.
mesh.position.set(0,0,0);
myVector3 = new THREE.Vector3 (100,200,300);
mesh.position = myVector3;
This applies to meshes, pointLights, presumably to all Object3D's but I havent tested further.
In the above example the mesh.position x,y,z values remain unchanged at (0,0,0). For illustration see this JSFiddle and compare lines 70 and 73.
//...The next line DOES NOT update Sphere_mesh.position.x
Sphere_mesh.position = NewPos_vector3;//...
//...The next line DOES update Sphere_mesh.position.x
Sphere_mesh.position.x = NewPos_vector3.x
In a debugger no console warning is given during execution that the assignment has not worked. In the very brief THREE.js migration notes for (r68 --> r69) I see something about an Object3D's position no longer being immutable but I don't know what that means.
Anyway, my question
Is there a standard THREE construct or function I can use to copy x,y,z values from a Vector3 object to the x,y,z values of a mesh.position rather than the effective, but verbose, form such as
mesh.position.x = myVector3.x;
mesh.position.y = myVector3.y;
mesh.position.z = myVector3.z; ?
e.g. something such as
mesh.position = F_Get_Object3DPosition_from_Vector3(myVector3); ?
I know it would be easy to write my own function but a standard THREE function would be more likely to evolve smoothly with future versions of THREE.
position beeing immutable means that the position property can not be changed.
so
mesh.position = anything;
won't work (but you already discovered this)
what you can do is not change the position, but you have to change position values.
in your case, the easiest way is
mesh.position.copy (myVector3);
I think you meant myVector3 not myVector3() in the last line... Anyway, I though that would work too but the thing is, you are applying a Vector to something that supposed to be a point/Vertex. Even if that worked in my opinion it wasn't the right way to do it. How about using a simple array:
mesh.position.set(0,0,0);
new_position = [100,200,300]
mesh.position.fromArray(new_position,0)
in which 0 is the starting index. So you can have multiple position sets in one array

Resources