jMonkeyEngine: BetterCharacterControl always bouncing - physics

I create 2 Spartials and set one as RigidBodyControl, second as BetterCharacterControl.
Both are boxes of sizes = (10f, 1f, 10f) and (0.5f,0.5f,0.5f).
floor = createFloor();
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(floor);
landscape = new RigidBodyControl(sceneShape, 0);
floor.addControl(landscape);
rootNode.attachChild(floor);
character = createCharacter();
player = new BetterCharacterControl(1F,1F,0.01f);
character.addControl(player);
rootNode.attachChild(character);
bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(character);
landscape.setPhysicsLocation(new Vector3f(0,-4,5));
player.warp(new Vector3f(0,0,0));
Now if i run it ... the character just bounces on the floor and i don't know why.
If i use the standard CharacterControl it works, though.
I'am aware that the character box doesn't match the shape but that shouldn't be the problem i guess.
Thanks in advance!

Did you try and turn on debugging?
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
Using debugging could help you see the collision shapes.

thanks for sharing the debug tip.
The problem was:
player = new BetterCharacterControl(1F,1F,0.01f);
You shouldn't create a Cylinder that has a smaller radius than the sizes.
player = new BetterCharacterControl(1F,1F,1F);
worked fine.

In my case, I needed to increase the height of my character by increasing BetterCharacterControl(1.5f, 1f, 1f) to BetterCharacterControl(1.5f, 6f, 1f). I'm not sure why this solved the problem for me, but it did.

Related

Setting Qtile Margins Dynamically Through Keyboard Input

I'm looking to set up keybindings to increase/decrease gaps and margins in Qtile similar to what the following does in i3-gaps:
bindsym $mod+equal gaps inner current plus 5
bindsym $mod+minus gaps inner current minus 5
bindsym $mod+Shift+equal gaps outer current plus 5
bindsym $mod+Shift+minus gaps outer current minus 5
I can somewhat get the equivalent of outer-gaps to work with the following code:
def increase_gap(qtile):
qtile.screens[0].top.size = screens[0].top.size+5
qtile.screens[0].right.size = screens[0].top.size+5
qtile.screens[0].left.size = screens[0].top.size+5
#margs = screens[0].bottom.margin
screens[0].bottom.margin[0] = screens[0].bottom.margin[0]+5
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()
def decrease_gap(qtile):
qtile.screens[0].top.size = max(screens[0].top.size-5, 0)
qtile.screens[0].right.size = max(screens[0].top.size-5, 0)
qtile.screens[0].left.size = max(screens[0].top.size-5, 0)
#margs = screens[0].bottom.margin
screens[0].bottom.margin[0] = max(screens[0].bottom.margin[0]-5, 0)
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()
Key([mod, "shift"], "equal", lazy.function(increase_gap), desc="Increase gap"),
Key([mod, "shift"], "minus", lazy.function(decrease_gap), desc="Decrease gap"),
I'm not sure this is the right way to do things, though. I'm not sure if this is supposed to be manipulated this way. I'm not really sure that the cmd_resize() function is what I should be using, however from trial and error it's what I've found to work. I'm not sure why the screen[0].bottom.size=20 (20 is the size of my bottom bar. I know I shouldn't hardcode, but I'm trying to produce a proof of concept before I clean the code) is needed, but the bar starts floating if I don't have that there. Finally, increasing and decreasing the gap gets close, but not quite to the original configuration. The gaps look slightly different than the original. So, I'm not sure this is the right way to accomplish this, and I could use the advice.
Secondly, though that gets close to accomplishing what I want on the outer gaps, I have not been able to make any headway to getting the inner gaps to work. I initially tried changing the margin parameter of a layout, and when that didn't work I tried simply initializing a new layout and replacing the old one as posted below, but neither approach worked.
def column_increase_margin(qtile):
current_margin = current_margin + 5
layouts[0] = layout.Columns(border_focus_stack='#d75f5f', margin=current_margin, border_width=0)
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()
I've tried going through the code here, but it's a big project and I'm struggling to make heads or tails from it.
Any advice would be appreciated.
If I understand what you want, you can add the following to the Layout class in libqtile/layout/base.py:
def cmd_increase_margin(self):
self.margin += 10
self.group.layout_all()
def cmd_decrease_margin(self):
new_margin = self.margin - 10
if new_margin < 0:
new_margin = 0
self.margin = new_margin
self.group.layout_all()
You can then add some keys in your config.py to increase and decrease margins. e.g.
KeyChord([mod], "m", [
Key([], "Up", lazy.layout.increase_margin()),
Key([], "Down", lazy.layout.decrease_margin())
],
mode="Margins"
),
I'm new to qtile, so maybe there is something wrong with the above approach, but it seems to work.

Matplotlib - Draw H and V line by specifying X or Y value on a plot

I was wondering today about how finding a specific value on a plot and drawing the right line that goes with. I used to do that on an old chart library, and I was wondering that perhaps this functionnality exist but I don't know how to find it.
The result should look like this: https://miro.medium.com/max/1070/1*Ckhi9soE9Lx2lIf9tPVLMQ.png
To provide some context, I'm doing a PCA over my data, and I would like to point out some thresholds at 97.5, 99 and 99.5% of explained cumuled variance.
Have a great day!
EDIT:
See Answer
As solved by ImportanceOfBeingErnest, here is the code:
whole_pca = PCA().fit(np.array(inputs['Scale'].tolist()))
cumul = np.cumsum(np.round(whole_pca.explained_variance_ratio_, decimals=3)*100)
over_95 = np.argmax(cumul>95)
over_99 = np.argmax(cumul>99)
over_995 = np.argmax(cumul>99.5)
plt.plot(cumul)
plt.plot([0,over_95,over_95], [95,95,0])
plt.plot([0,over_99,over_99], [99,99,0])
plt.plot([0,over_995,over_995], [99.5,99.5,0])
plt.xlim(left=0)
plt.ylim(bottom=80)
plt.ylabel('% Variance Explained')
plt.xlabel('# of Features')
plt.title('PCA Analysis')
Result in:
Thank you!

how can I draw pie charts in PsychoPy Builder

I want to create half a pie chart to use in an existing builder script and I'm not sure how to go about it. (its actually to implement a speedometer)
Does anyone have any suggestions?
I realise I'll need to dip into some python code.
This old posting in Google Groups https://groups.google.com/forum/#!topic/psychopy-users/JcnS7ZtuVlM gives some sample code utilising pylab but they couldn't get it to work when it was dropped into Builder.
Thanks,
I've worked out how to do this now so here's my method for the record.
# create 1st sector - use the **ori** parameter to control what bearing it
# starts on (0 is vertical)
rad1 = visual.RadialStim( win=win, name='rad1', color=[1,-1,-1],
angularCycles = 0, radialCycles = 0, radialPhase = 0.5, colorSpace = 'rgb',
ori= -90.0, pos=(0.5, -0.3), size=(0.3,0.3), visibleWedge=(0.0, 135.0) )
rad1.draw()
#now draw another sector next to it by using **ori** again to line them up
rad2 = visual.RadialStim( win=win, name='rad1', color=[-1,1,-1],
angularCycles = 0, radialCycles = 0, radialPhase = 0.5, colorSpace = 'rgb',
ori= 45.0, pos=(0.5, -0.3), size=(0.3,0.3), visibleWedge=(0.0, 45.0) )
rad2.draw()
This works fine in Builder, dropping it into a code segment and knowing that Builder uses a window called win
Note that this uses the default mode for size (-1 to 1) so it will look different on different screen sizes. you may want to change to cm (and calibrate your monitor) if you want it to be round.
Thanks to Jon P for his suggestion (via google groups) to use RadialStim)

MATLAB: Resizing a figure properly

I have a figure that I would like to resize and afterwards print as a PDF.
Using something like
set(hFig, 'PaperUnits', 'centimeters')
set(hFig, 'PaperSize', [x_B x_H]);
works as long as I do not resize the figure too drastically. If I reduce the height then at some points the xlabel moves out of the figure. I have searched a lot but only found an solution to manually resize the underlying axes-object
scalefactor = 0.96;
movefactor = 0.82;
hAx = get(gcf,'CurrentAxes');
g = get(hAx,'Position');
% 1=left, 2=bottom, 3=width, 4=height
g(2) = g(2) + (1-movefactor)/2*g(4);
g(4) = scalefactor*g(4);
set(hAx,'Position',g);
I do not like this approach since I have to manually adjust the two factors.
Before printing I set the 'interpreter' to 'latex' of all text-objects (if that is of concern).
Printing is achieved using
print(hFig, '-dpdf', '-loose', 'test.pdf');
I hoped to loosen the bounding box by using '-loose'. Any help is highly appreciated!
edit:
It seems that really the interpreter (none, tex, latex) plays a role in this. I got inspired by this post here (http://stackoverflow.com/questions/5150802/how-to-save-plot-into-pdf-without-large-margin-around) and came up with this solution:
tightInset = get(gca, 'TightInset');
position(1) = tightInset(1);
position(3) = 1 - tightInset(1) - tightInset(3);
if strcmpi(x_Interpreter,'latex')
position(2) = tightInset(2)+ 1*tightInset(4);
position(4) = 1 - tightInset(2) - 2*tightInset(4);
else
position(2) = tightInset(2)+ 0*tightInset(4);
position(4) = 1 - tightInset(2) - 1*tightInset(4);
end
set(gca, 'Position', position);
This may not solve your problem completely (it may just help clean up your code), but I found the fig code in the file exchange to be helpful: it lets you easily set the exact size of figures without bordering white space.

PChart - Show a fixed number of lablels in X-Axis

How to show only a fixed number of labels in X-Axis ??
I have tried "LabelSkip", but I think it works only with an interval and not with fixed number of labels.
Here is a print-screen of my chart:
Are you using pChart 1 or pChart2 ?
This can be achived in pChart 1 using setFixedScale
To draw a scale with a maximum value of 10 with 5 points use the following command before drawing the scale
$Graph->setFixedScale(0,10,5);
I know it has been a while since this was asked, but it may help someone:
$maxXLabels = 5; // How many labels on-screen?
$labelSkip = floor( count( $timestamp ) / $maxXLabels ); // how many should we skip?
$myPicture->drawScale(array("LabelSkip"=>$labelSkip));
I have used
"LabelSkip"=>(count($series)/10)
to have 10 labels on the X axis
Works fine for me
Joel Deutscher's answer worked for me. I would have up voted it, but I do not have enough stackoverflow reputation for that.
It works exactly as he said: Chart Width / MinDivHeight = Number of labels on the chart.
Here's my code
$scaleSettings = array("DrawXLines"=>FALSE,"Mode"=>SCALE_MODE_START0,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,"Pos"=>SCALE_POS_TOPBOTTOM, "MinDivHeight" => 50);
$pchart->chart->drawScale($scaleSettings);