Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I'm designing a small system that should be able to locate itself in the real world, it's basically an electric RC car with a PC mounted on it. This car should be able to navigate in the real world and know where it is on a map. Since it needs a good precision, GPS isn't an option (the best I can get is 4 meters, way over what I can accept) and encoding the wheels in any way is too expensive for my budget, so the workaround is to place a mouse under this car and use its feedback as the relative positioning system.
My first idea was to calculate the difference in the pixel distance between two instants (using a timer), I even tried to apply the same principle using the mouseMoved event, but the problem is still there: if I vary the speed of the mouse, the calculated distance varies too.
At this point I have no other ideas, what do you think is wrong with my approach?
public class Main extends Application {
public static void main(String args[]) {
launch(args);
}
private double cmToPixel = 1;
private int totalX;
private int totalY;
private Robot robot;
private int counter;
#Override
public void start(Stage primaryStage) throws Exception {
VBox pane = new VBox();
pane.setFillWidth(false);
pane.setMinWidth(200);
javafx.scene.control.TextArea textArea = new TextArea();
javafx.scene.control.TextArea logArea = new TextArea();
javafx.scene.control.TextArea debugArea = new TextArea();
pane.getChildren().addAll(textArea, logArea, debugArea);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.centerOnScreen();
robot = new Robot();
robot.mouseMove((int) (Screen.getPrimary().getBounds().getWidth() / 2), (int) (Screen.getPrimary().getBounds().getHeight() / 2));
scene.setOnMouseMoved(e -> {
double deltaX = e.getX() - Screen.getPrimary().getBounds().getWidth() / 2;
double deltaY = Screen.getPrimary().getBounds().getHeight() / 2 - e.getY() ;
totalX += deltaX;
totalY += deltaY;
textArea.appendText((totalX / cmToPixel) + " - " + (totalY / cmToPixel) + "\n");
debugArea.appendText(deltaX+" - "+deltaY+"\n");
logArea.appendText("Center: ["+(int) (Screen.getPrimary().getBounds().getWidth() / 2)+";"+(int) (Screen.getPrimary().getBounds().getHeight() / 2)+"] cursorPosition: "+e.getX()+" - "+e.getY()+"\n");
robot.mouseMove((int) (Screen.getPrimary().getBounds().getWidth() / 2), (int) (Screen.getPrimary().getBounds().getHeight() / 2));
});
primaryStage.show();
primaryStage.setFullScreen(true);
}}
if you want to reproduce my results, just mark two lines on a piece of paper and try to run the mouse between those lines at different speeds while keeping an eye on the program
The reported distances of a mouse device depend on the speed at which you move the mouse. This is normally desired if a mouse is used for what it is made for but in your case this is a problem. I'd try to switch this feature of in your mouse settings. Maybe this link can help you.
https://askubuntu.com/questions/698961/disable-mouse-acceleration-in-ubuntu-15-10
If you're reading this post you may want to know that yes, the problem was with acceleration, and even when "disabled" something still doesn't work out, I solved this problem by connecting a PS2 mouse to an Arduino, and with JSSC I ask it the delta X and Y since last check (take a look here http://www.instructables.com/id/Optical-Mouse-Odometer-for-Arduino-Robot/)
Related
I am trying to find out how to get a mouse working inside RPCS3 emulator for a game (Ghost Recon Future Soldier with patch 1.05)
There is a library that supports injecting the mouse but doesn't support the game I am trying to play. After a lot of digging, I found a library that actually implements mouse injection in a few games.
Sample implementation for the KillZone3 game to support mouse injection looks like this in C#
using KAMI.Core.Cameras;
using KAMI.Core.Utilities;
using System;
namespace KAMI.Core.Games
{
public class Killzone2PS3 : Game<HVecVACamera>
{
DerefChain m_hor;
DerefChain m_vert;
public Killzone2PS3(IntPtr ipc, string version) : base(ipc)
{
uint baseAddress = version switch
{
"01.01" => 0x117e740 + 0x234,
"01.29" => 0x11B0540 + 0x234,
_ => throw new NotImplementedException($"{nameof(Killzone2PS3)} [v'{version}'] is not implemented"),
};
var baseChain = DerefChain.CreateDerefChain(ipc, baseAddress, 0x0);
m_vert = baseChain.Chain(0x80).Chain(0x5c).Chain(0x11c).Chain(0x78);
m_hor = baseChain.Chain(0x78).Chain(0x0).Chain(0x68).Chain(0xc).Chain(0x90);
}
public override void UpdateCamera(int diffX, int diffY)
{
if (DerefChain.VerifyChains(m_hor, m_vert))
{
m_camera.HorY = IPCUtils.ReadFloat(m_ipc, (uint)m_hor.Value);
m_camera.HorX = IPCUtils.ReadFloat(m_ipc, (uint)(m_hor.Value + 4));
m_camera.Vert = IPCUtils.ReadFloat(m_ipc, (uint)m_vert.Value);
m_camera.Update(diffX * SensModifier, -diffY * SensModifier);
IPCUtils.WriteFloat(m_ipc, (uint)m_hor.Value, m_camera.HorY);
IPCUtils.WriteFloat(m_ipc, (uint)(m_hor.Value + 4), m_camera.HorX);
IPCUtils.WriteFloat(m_ipc, (uint)m_vert.Value, m_camera.Vert);
}
}
}
}
Main lines in the above program are those addresses which I believe are associated with the camera pointer stored in memory obtained mostly with Cheat Engine.
What is the process required to find these pointers for my game. I am aware that is may be different for each game but I could really use some direction here. Where do I start? How do I narrow down till I arrive at this pointer
What a coincidence, I am also doing the exact same thing on RPCS3 right now. After digging around I've found some videos that discuss into how to use Cheat Engine to find where a player's position and camera would be stored. It involves making a lot of separate scans in Cheat Engine to search for unknown values that are increasing/decreasing.
This video seems to be the closest thing to what you are looking for:
https://www.youtube.com/watch?v=yAl_6qg6ZnA
You should also make sure you set up Cheat Engine so it works with RPCS3 correctly as shown here:
https://exvsfbce.home.blog/2019/08/24/basic-cheat-engine-setup-on-rpcs3/
After you've found the correct pointer for the camera it should be fairly easy to implement it into the library by making your own class in the Games folder.
I'm trying to make a prototype for my interactive media class but I hit a little hiccup on the progress. I was following a tutorial where everything was running smoothly till I got to using the Animator. I followed every instruction step by step during the tutorial I was watching. Basically, my 2D Sprite Character is stuck in the fall animation whenever I play the game rather than it being in the default idle animation like it's supposed to be. I tried deleting and recreating the animation paths but that didn't work. I even tried deleting everything and putting everything in from scratch back into the animator. I did check off exit time, set the duration for zero, and give the "state" which is what I called the in their respective numbers but it's still stuck on falling. when I jump with my character the run and idle animation seem to be working. It's like everything reversed with falling. It also gave me the difference in effective length is too big as an error. I tried adding more frames to my falling animation to see if that would fix and also tried checking and unchecking loop time and It's still stuck on the fall. If anyone knows what's wrong with the animator please let me know. I don't think it has anything to do with the code but better safe than sorry so I'll put it here. If anyone has the answer to my issue please get back to me when you can and thank you!
PlayerMovement.cs: `
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody2D rb;
private SpriteRenderer sprite;
private Animator anim;
private float dirX = 0f;
[SerializeField] private float moveSpeed = 12f;
[SerializeField] private float jumpForce = 16f;
private enum MovementState { idle, running, jumping, falling }
// Start is called before the first frame update
private void Start()
{
rb = GetComponent<Rigidbody2D>();
sprite = GetComponent<SpriteRenderer>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
private void Update()
{
dirX = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(dirX * moveSpeed, rb.velocity.y);
if (Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
UpdateAnimationState();
}
private void UpdateAnimationState()
{
MovementState state;
if (dirX > 0f)
{
state = MovementState.running;
sprite.flipX = false;
}
else if (dirX < 0f)
{
state = MovementState.running;
sprite.flipX = true;
}
else
{
state = MovementState.idle;
}
if (rb.velocity.y > .1f)
{
state = MovementState.jumping;
}
else if (rb.velocity.y > -.1f)
{
state = MovementState.falling;
}
anim.SetInteger("state", (int)state);
}
}
This is my Animator in Unity
The Player Falling Inspector
Player Running -> Player Falling
Player Idle -> Player Falling
Player Jumping -> Player Falling
Is there a way that a mathematical expression can be formatted in JavaFX during input? Something like a TextArea that behaves exactly as the mathquill editor, which is for web applications?
If not, would it be possible to create a custom TextField / TextArea to provide such functionality? I have not yet looked into this so any guidance or suggestions are welcome :)
The only workaround I came up with is to input the expression as a String and convert it to an image using jLaTeXmath, which is not preferred as the end result should be an editable equation.
Short example on embedding jLaTeXmath:
This is done by converting a TeX expression to a BufferedImage that can be placed on a Pane. See below the code for the conversion:
/**
* Converts LaTeX code to a BufferedImage
* #param latex
*/
public static BufferedImage latexToImage(String latex){
String start ="\\begin{array}{l}";
start += latex;
start += "\\end{array}";
TeXFormula formula = new TeXFormula(start);
// Note: Old interface for creating icons:
//TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
// Note: New interface using builder pattern (inner class):
TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(65f).build();
icon.setInsets(new Insets(1, 1, 1, 1));
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
g2.setComposite(AlphaComposite.Clear);
// g2.setColor(Color.WHITE);
g2.fillRect(0,0,icon.getIconWidth(),icon.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
g2.setComposite(AlphaComposite.Src);
icon.paintIcon(null, g2, 0, 0);
/*
File file = new File("Example2.png");
try {
ImageIO.write(image, "png", file.getAbsoluteFile());
} catch (IOException ex) {}
*/
return image;
}
The image can then be converted and set in a ImageView in JavaFX as folllows:
BufferedImage bimage = latexToImage("a = 2 \cdot x");
Image image = SwingFXUtils.toFXImage(bimage , null);
// have an ImageView in your scene and set the image
imgView.setImage(image );
The next coming versions of JavaFX support MathML by using a HTMLEditor Control :
JavaFX 8 Update 192 included in Java 8 Update 192
JavaFX 11.
Follow this link Java Early Access Download to reach the early access to these versions.
I'm afraid that what you are looking for doesn't exist yet.
There is a project in the JavaFX GitHub Reprository, but it's long term project.
About MathQuill, it seems that it is a JavaScript code. Or HTMLEditor uses an implementation of WebKit and can execute JavaScript code. It could be a short term solution.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to generate an UI where someone can navigate through the path of a tree structure. Here is an example of what I want, taken from JavaFX Scene Builder.
Depending on the actual position in an TreeView, this UI is updated. By clicking on individual items the tree is updated.
My question:
What Nodes/Controls are best used for this approach? (no full code required. Just mention the name of the controls).
My first idea is to generate a row of buttons closely to each other, but maybe there are better ideas.
Thanks.
You can use ControlsFx's BreadCrumbBar
Pane root = ...
Label selectedCrumbLbl = new Label();
BreadCrumbBar<String> sampleBreadCrumbBar = new BreadCrumbBar<>();
root.getChildren().addAll(sampleBreadCrumbBar, selectedCrumbLbl);
TreeItem<String> model = BreadCrumbBar.buildTreeModel("Hello", "World", "This", "is", "cool");
sampleBreadCrumbBar.setSelectedCrumb(model);
sampleBreadCrumbBar.setOnCrumbAction(new EventHandler<BreadCrumbBar.BreadCrumbActionEvent<String>>() {
#Override public void handle(BreadCrumbActionEvent<String> bae) {
selectedCrumbLbl.setText("You just clicked on '" + bae.getSelectedCrumb() + "'!");
}
});
https://github.com/controlsfx/controlsfx/blob/master/controlsfx-samples/src/main/java/org/controlsfx/samples/button/HelloBreadCrumbBar.java
The chosen solution did not work for me. I had to listen to the selectedCrumbProperty.
TreeItem<String> helloView = new TreeItem("Hello");
TreeItem<String> worldView = new TreeItem("World");
hellowView.getChildren().add(worldView);
TreeItem<String> thisView = new TreeItem("This");
worldView.getChildren().add(thisView);
TreeItem<String> isView = new TreeItem("is");
thisView.getChildren().add(isView);
BreadCrumbBar<String> sampleBreadCrumbBar = new BreadCrumbBar<>(helloView);
sampleBreadCrumbBar.setSelectedCrumb(helloView);
sampleBreadCrumbBar.selectedCrumbProperty().addListener((observable, oldValue, newValue) -> {
System.out.println(newValue);
if (newValue == worldView) {
//load this view
}
});
I typed this directly into the answer. There may be errors. Leave a note.
Here's the code I use:
public partial class Form1 : Form
{
private ILPlotCube plotcube_ = null;
private ILSurface surface_ = null;
public Form1()
{
InitializeComponent();
ilPanel1.Driver = RendererTypes.OpenGL;
}
private void ilPanel1_Load(object sender, EventArgs e)
{
var scene = new ILScene();
plotcube_ = scene.Add(new ILPlotCube(twoDMode: false));
plotcube_.MouseDoubleClick += PlotCube_MouseDoubleClick;
ilPanel1.Scene = scene;
}
private void PlotCube_MouseDoubleClick(object sender, ILMouseEventArgs e)
{
ResetSurface();
e.Cancel = true;
e.Refresh = true;
}
private void ResetSurface()
{
using (ILScope.Enter())
{
ILArray<float> array = ILMath.tosingle(ILSpecialData.sincf(1000, 1000));
if (surface_ == null)
{
surface_ = new ILSurface(0);
surface_.Fill.Markable = false;
surface_.Wireframe.Visible = false;
plotcube_.Add(surface_);
}
surface_.UpdateColormapped(array);
surface_.UseLighting = false;
}
plotcube_.Plots.Reset();
}
}
Each call to ResetSurface() takes a few seconds to complete: ~6s in Debug and ~4s in Release mode.
Once the surface is updated, though, rotation and pan operations are very fluid.
The smaller the surface, the faster the update.
Is there a more efficient way to update the surface positions/colors buffers?
Note: using IlNumerics 3.2.2 Community Edition on Windows 7 laptop with dual graphics (Intel HD 4000 + GeForce GT 650M), with nvidia card activated.
There is nothing obviously wrong with your code. A common pitfall is the wireframe color. If it is left to be semitransparent (default), the necessary sorting would slow the rendering down. But you have already set it to Visible = false.
So on my machine (win 7, T430 notebook, i7 and similar graphics) it takes <2 sec to update (Release with no debugger attached!). I am afraid, that's just what it takes. There is a lot of stuff going on in the back ...
#Edit It might be faster to precompute the colors and provide them as discrete color using ILSurface.UpdateRGBA(). You will have to try and use a profiler to investigate the bottleneck. Another option - since you are after a simple imagesc-style plot - is to build the imagesc on your own: ILTriangles(-strip) ist much more slim and probably gives more option to increase the update speed. However, you will have to do a considerable amount of reordering / vertex generation / color computation on your own. Also, this won't give you the colorbar support of ILSurface.
#Edit: You can use the ILImageSCPlot class as a slim replacement for ILSurface. The documentation is here: http://ilnumerics.net/imagesc-plots.html