I implemented the speedometer in my project by referring the code as found in the below link.
I need to animate the speedometer needle till i get the result from server, and once i got the result , i need to set the needle to proper value based on some calculation.
I am not understanding how to do it.
Please help me with some solution.
https://github.com/ntoskrnl/SpeedometerView/blob/master/CardioMoodSpeedometerView/SpeedometerView/src/main/java/com/cardiomood/android/speedometer/SpeedometerView.java
private SpeedometerView speedometer;
// Customize SpeedometerView
speedometer = (SpeedometerView) v.findViewById(R.id.speedometer);
// Add label converter
speedometer.setLabelConverter(new SpeedometerView.LabelConverter() {
#Override
public String getLabelFor(double progress, double maxProgress) {
return String.valueOf((int) Math.round(progress));
}
});
// configure value range and ticks
speedometer.setMaxSpeed(300);
speedometer.setMajorTickStep(30);
speedometer.setMinorTicks(2);
// Configure value range colors
speedometer.addColoredRange(30, 140, Color.GREEN);
speedometer.addColoredRange(140, 180, Color.YELLOW);
speedometer.addColoredRange(180, 400, Color.RED);
Check the readme. Here you will find above code. And i think you need to look for how to change the needle.
And then call the public method SetSpeed(double speed) on the speedometer object.
A simple look through the code in your link provides the answer.
Related
I'm trying to move my drone through a set of 2D coordinates like my code below
However, after I pressed the start timeline button, the drone only took off and didn't move to any point
I don't know what happens with my code right now as I've tried to follow DJI Sample Code for the MissionControl part
Please have a check a help me with this
Thanks in advance
Here is my code
private void initTimeline()
{
List<TimelineElement> elements = new ArrayList<>();
mMissionControl = MissionControl.getInstance();
final TimelineEvent preEvent = null;
MissionControl.Listener listener = new MissionControl.Listener()
{
#Override
public void onEvent(#Nullable TimelineElement TimelineElement, TimelineEvent event, DJIError error)
{
updateTimelineStatus(TimelineElement, event, error);
}
};
showToast("Initialize Time Line System");
elements.add(new TakeOffAction());
GoToAction set_altitude = new GoToAction(new LocationCoordinate2D(0,0),2);
elements.add(set_altitude);
GoToAction go_2 = new GoToAction(new LocationCoordinate2D(1,1),2f);
elements.add(go_2);
GoHomeAction go_home = new GoHomeAction();
elements.add(go_home);
mMissionControl.scheduleElements(elements);
mMissionControl.addListener(listener);
}
private void startTimeline()
{
showToast("Start Time Line");
mMissionControl.getInstance().startTimeline();
}
private void stopTimeline()
{
showToast("Stop Time Line");
mMissionControl.getInstance().stopTimeline();
}
I believe that I answered you in email but I see a few issues in your code:
The GoToAction is telling the aircraft to move to location 0, 0 (latitude/longitude) at a elevation 2 meters.
There are a few issues with this move.
First, unless you are flying at location 0, 0 (or very near the location) then the aircraft will return an error similar to "TOO_FAR, indicating the move is beyond the flight distance limits.
The second issue is the altitude, I believe there is a minimum altitude allowable but I'm not certain.
Are you really flying in the middle of the Atlantic, at location 0, 0? If you are not, I suggest trying a GoToAction with a location nearer to where you are taking off. The sample shows a calculation to move 3m and I suggest you could use that and calculate a location 3m away from takeoff (using the aircraft's home location and moving from that).
Also, the mission listener will report errors (the last parameter DjiError) reports any issues with the timeline; when not null, I suggest logging the error and it will inform you what the problem is and make correction easy.
Best of luck!
I'm trying to make a simple bit of code that will detect whether a model was clicked on. So far the best method I've seen is to create some sort of rectangle around the mesh and detect with Gdx.input.justTouched() to get the x,y coordinates, and then check if the rectangle contains the coordinates returned by justTouched().
I have no idea if there's a better way to do this, some kind of mesh onClick listener or something that LibGDX has in place that I'm unaware of (I've been scouring Google and the javadocs but I can't seem to find anything). I don't really need to deal with the z-axis coordinate, at least I don't think so. I only have the one PerspectiveCamera and it's not going to be moving around that much (not sure if this matters?)
Anyways, in my render() method I have:
if (Gdx.input.justTouched()) {
//this returns the correct values relative to the screen size
Vector2 pos = new Vector2(Gdx.input.getX(), Gdx.input.getY());
//I'm not sure how to get the correct rectangle to see what the
//width and height are for the model relative to the screen?
Rectangle modelBounds = new Rectangle(<<not sure what to put here>>);
if (modelBounds.contains(pos.x, pos.y) {
System.out.println("Model is being touched at: " + pos.x + ", " + pos.y);
}
}
I'm really not sure if this is the correct way to do this. I can get the position of the model with:
modelInstance.getNode("Node1").globalTransform.getTranslation(new Vector3());
but I'm not sure how to get the width and height as a rectangle relative to the screen size, if it's even possible.
I'm also unsure if this would cause massive lag, as I'm going to have about 7 nodes total that I need to detect if they're clicked on or not.
Is there a better way to do this? If not, is there a way to get the model width & height relative to the screensize (or camera, maybe)?
EDIT: Read about using Bounding Boxes, seems like what I need. Not quite sure how to implement it properly, however. I've changed my code to such:
public ModelInstance modelInstance;
public BoundingBox modelBounds;
#Override
public void create() {
...
//omitted irrelevant bits of code
modelInstance = new ModelInstance(heatExchangerModel);
modelBounds = modelInstance.calculateBoundingBox(new BoundingBox());
}
#Override
public void render() {
...
if (Gdx.input.justTouched()) {
Vector3 pos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
System.out.println(pos);
if (modelBounds.contains(pos)) {
System.out.println("Touching the model");
}
}
}
I'm not really sure what the output of BoundingBox is supposed to be, or how the numbers it gives me correlates to the position in a 2d space. Hmm..
EDIT2: Think I'm getting closer.. Read about Rays and the .getPickRay method for my PerspectiveCamera. .getPickRay seems to return completely unusable numbers though, like really tiny numbers. I think I need to do something like:
if (Gdx.input.justTouched()) {
Vector3 intersection = new Vector3();
Ray pickRay = perspectiveCamera.getPickRay(Gdx.input.getX(), Gdx.input.getY());
Intersector.intersectRayBounds(pickRay, modelBounds, intersection);
}
and then intersection should give me the point where they overlap. It appears to be not working, however, giving me really small numbers like (4.8066642E-5, 2.9180354E-5, 1.0) .. hmmm..
I followed every instruction I could find, tried various ways to implement this, always with the same symptom: Nothing happens...
Expectation:
Have an image that is fading from 100% transparent to 0% transparent.
I have this FadingImage class:
public class FadingImage{
private FadeTransition ft;
public FadingImage(String imgName,int posX, int posY, double from, double to, Group root) {
ImageView img = new ImageView(imgName);
ft = new FadeTransition(Duration.millis(1000));
ft.setNode(img);
ft.setFromValue(from); //sets the start opacity value
ft.setToValue(to); //sets the target opacity value
ft.setCycleCount(1);
ft.setAutoReverse(false);
img.setTranslateX(posX);
img.setTranslateY(posY);
root.getChildren().add(img);
}
public void play(){
ft.playFromStart();
}
}
And I call it like this:
FadingImage fi = new FadingImage("images/dock1.png",500, 500, 0.0, 1.0, root);
fi.play();
I am getting no exceptions whatsoever.
If I add a System out in the play method, it shows it.
I feel like I am missing something basic here, I just don't find it...
The code is correct. The parameters used were incorrect, as the image was displayed outside the screen.
So I'm writing some tools for my program to deal with basic configurations, reading settings from a data file, and then making those settings the active configuration. I'm also building in an error checking mechanism to make sure that settings are formatted correctly and have valid values.
I want to check to see what the current devices supported resolutions are, and I want to compare that to the resolution specified in the data file. Is there an easy way to do this in libGDX that I'm missing? I know that LWJGL has a function that will give you an array of the supported resolutions, but I don't want to reinvent the wheel.
I'm looking for something like:
boolean isValidResolutionForDevice(int width, int height)
Am I going to have to write this myself? Or does this exist already? It seems to me to be such a useful function that it must have been written into the libraries somewhere.
There actually is a way to do this. The main com.badlogic.gdx.Application interface has a getGraphics() method, and the com.badlogic.gdx.Graphics class returned from that has getDisplayModes() method, which returns DisplayMode[]. DisplayMode basically looks like this (comments and constructor removed):
public class DisplayMode {
/** the width in physical pixels **/
public final int width;
/** the height in physical pixles **/
public final int height;
/** the refresh rate in Hertz **/
public final int refreshRate;
/** the number of bits per pixel, may exclude alpha **/
public final int bitsPerPixel;
}
And then you can scan through these to see if the resolution in question is supported or not.
The only bit of annoying news is because getGraphics() is on the Application object, it doesn't seem like you can query for the available graphics modes until after the Application object (e.g. LwjglApplication) has been created. So perhaps you pick an arbitrary resolution (e.g. 1024x768), start the game, then immediately switch to a supported resolution if the original wasn't actually supported (and optionally let the user pick in a settings menu).
I came across the method I believe you're referring to, org.lwjgl.opengl.Display.getAvailableDisplayModes(), and...honestly I'd just use this one for your use case. You'd pretty much just be iterating over it with a simple conditional inside. Not exactly reinventing anything.
Unfortunately, there is no ready solution in libgdx, I solved it like this:
private Map<Integer, Integer> supportedReolutions;
private String graphicFolder;
supportedReolutions = new HashMap<Integer, Integer>();
supportedReolutions.put(1024, 768);
supportedReolutions.put(1080, 1920);
supportedReolutions.put(1200, 1920);
supportedReolutions.put(2048, 1536);
supportedReolutions.put(480, 800);
supportedReolutions.put(640, 1136);
graphicFolder = "1080x1920";
/**
* Chose the folder with best graphic for current device
*/
private void setCurrentResolutionFolder() {
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
if (supportedReolutions.containsKey(width)) {
if (supportedReolutions.get(width) == height) {
graphicFolder = String.valueOf(width) + "x"
+ String.valueOf(height);
}
}
}
We are using JFreeChart to make XY plots and we have a feature request to do a crosshair that moves along with the mouse and highlights the data point that most closely maps to the x-value of the mouse. You can see a similar example at Google Finance - http://www.google.com/finance?q=INDEXDJX:.DJI,INDEXSP:.INX,INDEXNASDAQ:.IXIC.
Those Google charts only highlight the current value (we want to do that and also show crosshairs), but they show the live mouse interaction we are looking for.
Anyone have any elegant suggestions?
Thanks.
I got this working using a mouse listener and the CrosshairOverlay class. After I get back from holiday travel, I will post my code. It ended up being not too difficult.
Sorry, I forgot about this!
First, you want to calculate the x, y values for where you want your crosshair. For me, I wanted it to move along the points of our line, so I calculated the closest x value and used that data pair for x, y.
Then I call this method:
protected void setCrosshairLocation(double x, Double y) {
Crosshair domainCrosshair;
List domainCrosshairs = crosshairOverlay.getDomainCrosshairs();
if (domainCrosshairs.isEmpty()) {
domainCrosshair = new Crosshair();
domainCrosshair.setPaint(BlueStripeColors.LIGHT_GRAY_C0);
crosshairOverlay.addDomainCrosshair(domainCrosshair);
}
else {
// We only have one at a time
domainCrosshair = (Crosshair) domainCrosshairs.get(0);
}
domainCrosshair.setValue(x);
if (y != null) {
Crosshair rangeCrosshair;
List rangeCrosshairs = crosshairOverlay.getRangeCrosshairs();
if (rangeCrosshairs.isEmpty()) {
rangeCrosshair = new Crosshair();
rangeCrosshair.setPaint(BlueStripeColors.LIGHT_GRAY_C0);
crosshairOverlay.addRangeCrosshair(rangeCrosshair);
}
else {
// We only have one at a time
rangeCrosshair = (Crosshair) rangeCrosshairs.get(0);
}
rangeCrosshair.setValue(y);
}
}
Note that crosshairOverlay is an instance of CrosshairOverlay.
JFreeChart can't render a sub-section of a chart, so you'll want to do something that doesn't require repainting the chart. You could write your chart to a BufferedImage and store that in memory, then have a custom component which uses the buffered chart as the background image, and draws crosshairs and other popup windows over it.
There are methods in JFreeChart to get the data point for a given coordinate on a rendered chart. Don't recall what these are off the top of my head. Depending on your needs, you might consider rendering your own chart data, it's not as hard as you'd think.
The first thing that comes to my mind would be to write a custom Cursor and set it on your chart. It can have a reference to the chart and highlight the x value that's consistent with the Cursor's x/y location.
This worked for me. I set the
chartPanel.addChartMouseListener(new ChartMouseListener() {
public void chartMouseMoved(ChartMouseEvent event)
{
try
{
double[] values = getCrossHairValue(event);
plot.clearRangeMarkers();
plot.clearDomainMarkers();
Marker yMarker = new ValueMarker(values[1]);
yMarker.setPaint(Color.darkGray);
plot.addRangeMarker(yMarker);
Marker xMarker = new ValueMarker(values[0]);
xMarker.setPaint(Color.darkGray);
plot.addDomainMarker(xMarker);
chartPanel.repaint();
} catch (Exception e)
{
}
}
}