libgdx button up down no effect - button

val playTexture = assetManager?.get(A.image.gamePlayBtn, Texture::class.java)
val skin: Skin = Skin()
skin.add("up", TextureRegion(playTexture, 0, 0, 296, 96))
skin.add("down", TextureRegion(playTexture, 0, 96, 296, 96))
val playButton: ImageTextButton = ImageTextButton("PLAY THE GAME", with(ImageTextButton.ImageTextButtonStyle()) {
up = skin.getDrawable("up")
down = skin.getDrawable("down")
font = BitmapFont()
font.data.setScale(3f)
font.color = Color.ORANGE
this
})
OnClick events work ok, but there is no button background change for onClicked state(down). Where I'm wrong?

I've tested your code, that's working fine. Added complete text code :
class Main : ApplicationAdapter(){
internal lateinit var stage: Stage
override fun create() {
stage= Stage()
stage.setDebugAll(true)
Gdx.input.setInputProcessor(stage)
var skin= Skin()
var tex1 =Texture("badlogic.jpg")
skin.add("up", TextureRegion(tex1, 0, 0, 100, 50))
skin.add("down", TextureRegion(tex1, 0, 96, 100, 50))
var playButton: ImageTextButton = ImageTextButton("Play The Game", with(ImageTextButton.ImageTextButtonStyle()){
up = skin.getDrawable("up")
down = skin.getDrawable("down")
font = BitmapFont()
font.data.setScale(3f)
font.color = Color.ORANGE
this
});
playButton.setPosition(0F,100F)
playButton.addListener(object : ClickListener(){
override fun clicked(event: InputEvent?, x: Float, y: Float) {
print("clicked")
super.clicked(event, x, y)
}
})
stage.addActor(playButton)
}
override fun render() {
Gdx.gl.glClearColor(1f, 0f, 0f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
stage.draw()
stage.act()
}
}

You have to update your button.
There is updateImage() function, but its protected so u have to do it using Stage.
So here is what u do:
Create stage.
Add your button to stage.
Call stage.draw() in render function.
...
Stage stage = new Stage();
//create button
stage.addActor(playButton);
...
#Override
public void render() {
stage.draw();
}

Related

How to define a heavy object in Matter JS

To explain better what I need, think about a tank and a can of soda.
No matter what the speed of that can of soda would be, the tank wouldn't move if it's hit.
But the tank should be able to move when force is applied to it.
Already opened an issue here with more details:
https://github.com/liabru/matter-js/issues/841
And I also made an example here for what I need.
var Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Bodies = Matter.Bodies,
Body = Matter.Body;
var engine = Engine.create();
engine.positionIterations = 10;
engine.velocityIterations = 8;
var render = Render.create({
element: document.body,
engine: engine,
options: {
width: 800,
height: 400,
wireframes: false
}
});
engine.world.gravity.y = 0;
var topWall = Bodies.rectangle(400, 50, 720, 20, { isStatic: true });
var leftWall = Bodies.rectangle(50, 210, 20, 300, { isStatic: true });
var rightWall = Bodies.rectangle(750, 210, 20, 300, { isStatic: true });
var bottomWall = Bodies.rectangle(400, 350, 720, 20, { isStatic: true });
var ball = Bodies.circle(100, 200, 5, {
friction: 0.05,
frictionAir: 0.05,
density: 0.001,
restitution: 0.2
});
var bigBox = Matter.Bodies.rectangle(500, 200, 120, 120, {
inertia: Infinity,
frictionAir: 1,
friction: 1,
density: 0.1
});
World.add(engine.world, [topWall, leftWall, rightWall, bottomWall, ball, bigBox]);
Engine.run(engine);
Render.run(render);
// CMD + SHIFT + 7 to reload
$('.shoot').on('click', function () {
var speed = 0.02;
var angle = 0;
let vector = Matter.Vector.create(Math.cos(angle) * speed, Math.sin(angle) * speed);
Body.applyForce(ball, ball.position, vector);
});
https://codepen.io/dmerlea/pen/BaoQJYK

Is there a better way of writing this data structure in Dart?

Map in Dart is an hash table, am I right?
Map starsData = {
'stars':{
'star1': {'x': 0, 'y': 10},
'star2': {'x': 0, 'y': 10}
}
};
This object below in JavaScript can be accessed as an hash table, faster!! I just want to do the some in Dart, but I am not sure if the best way is using Map.
const starsData = {
stars:{
'star1': {'x': 0, 'y': 10},
'star2': {'x': 0, 'y': 10}
}
};
I have rewritten your JavaScript implementation (based on the project your linked: https://github.com/ToniCalfim/fallingstars/blob/master/index.js) in Dart:
Can also be tested with:
https://dartpad.dev/900989f4e35e5a61200e4ad04ecd399a
import 'dart:html';
import 'dart:math' as math;
const starsDiameter = 1.25;
const colorPallete = [
'white',
'yellow',
'blue',
'red',
'orange',
'turquoise',
'purple',
'green',
'lightblue',
'lightyellow',
'lightgreen',
'darkred',
'darkblue',
'darkorange',
'darkturquoise',
'darkgreen'
];
final math.Random _rnd = math.Random();
int getRandomNumber(int min, int max) => min + _rnd.nextInt(max - min);
class Star {
int x, y;
int positionX = getRandomNumber(2, 650);
int positionY = getRandomNumber(3, 125);
double diameter = starsDiameter;
int pulsing = 0;
int blinking = 0;
int timeToFall = getRandomNumber(0, 7500);
int velocityToFall = getRandomNumber(1, 5);
int directionToFall = getRandomNumber(-1, 1);
String color = colorPallete[getRandomNumber(0, colorPallete.length)];
Star() {
x = positionX;
y = positionY;
}
}
final List<Star> stars = List.generate(175, (_) => Star());
void update() {
for (final currentStar in stars) {
final currentTimeToFall = currentStar.timeToFall;
if (currentTimeToFall != 0) {
currentStar.timeToFall = currentTimeToFall - 1;
} else {
final currentVelocityToFall = currentStar.velocityToFall;
final currentAngleToFall = currentStar.directionToFall;
final currentPositionX = currentStar.x;
final currentPositionY = currentStar.y;
currentStar.x = currentPositionX + 1 * currentAngleToFall;
currentStar.y = currentPositionY + currentVelocityToFall;
}
}
}
final CanvasElement canvas = querySelector('#canvas') as CanvasElement;
final CanvasRenderingContext2D context2D = canvas.context2D;
void drawStars() {
context2D.clearRect(
0, 0, context2D.canvas.width, context2D.canvas.height); // Clear canvas
for (final currentStar in stars) {
context2D.beginPath();
context2D.fillStyle = currentStar.color;
context2D.arc(currentStar.x, currentStar.y, starsDiameter, 0, 2 * math.pi);
context2D.fill();
context2D.closePath();
}
}
void animateLoop([num highResTime]) {
update();
drawStars();
window.requestAnimationFrame(animateLoop);
}
void main() {
animateLoop();
}
By looking at your code I could not see any reason why the stars should be saved in a Map or other Hash tables related structure. You are using the stars in two ways: draw and update. In both cases your are just going through all the stars which can be done by using a simple list and iterate over all elements.
I should add that I am not a front-end programmer and I cannot really judge if the way your are drawing the 2D canvas is the most efficient way to do that. My converted code are only are attempt to show how the data could be structured in Dart.

ASP.NET/SQL Not retrieving correct value from database

So I'm trying to create a monopoly web game using asp.net. I was having issues with variables being saved due to the postback, so I've created a database which stores all the info about the players and squares etc. The problem I'm having now however is for some reason the current player ID isn't being stored/retrieved correctly. I apologise for the relatively long wall of code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace Monopoly_Web
{
public partial class WebForm1 : System.Web.UI.Page
{
List<Player> players = new List<Player>();
List<Square> squares = new List<Square>();
Player currentPlayer;
Square CurrentSquare;
SQLDatabase.DatabaseTable players_table = new SQLDatabase.DatabaseTable("PlayersTable");
SQLDatabase.DatabaseTable squares_table = new SQLDatabase.DatabaseTable("SquaresTable");
SQLDatabase.DatabaseTable gameinfo_table = new SQLDatabase.DatabaseTable("GameInfoTable");
int currentPlayerID = 0;
int currentSquareID = 0;
int freeParkingAmount = 500;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
readFromDatabase();
}
}
//------------------------------------------------------------------------------------------------------------------------------------
// MAIN GAME BUTTONS
//------------------------------------------------------------------------------------------------------------------------------------
protected void RollDiceButton_Click(object sender, EventArgs e)
{
int dice = new Random((int)DateTime.Now.Ticks).Next(1, 7); // Pick a number from 1 to 6 and add it to the current position.
diceRoll.Visible = true;
diceRoll.Text = "You rolled a " + dice.ToString();
currentPlayer.SetPosition(MovePlayer(dice));
CurrentSquare = squares[currentPlayer.GetPosition()];
updateDisplay();
RollDiceButton.Enabled = false;
EndTurnButton.Enabled = true;
writeToDatabase();
}
protected void BuyButton_Click(object sender, EventArgs e)
{
writeToDatabase();
}
protected void EndTurnButton_Click(object sender, EventArgs e)
{
diceRoll.Visible = false;
buyLabel.Visible = false;
payLabel.Visible = false;
RollDiceButton.Enabled = true;
BuyButton.Enabled = false;
EndTurnButton.Enabled = false;
//checkBankruptcy();
changeActivePlayer();
currentPlayerLabel.Text = "Current Player: " + currentPlayerID.ToString();
updateDisplay();
writeToDatabase();
}
protected void ResumeButton_Click(object sender, EventArgs e)
{
resumeGame();
RollDiceButton.Enabled = true;
EndTurnButton.Enabled = true;
StartButton.Visible = false;
ResumeButton.Visible = false;
}
//------------------------------------------------------------------------------------------------------------------------------------
// PLAYER MOVEMENT
//------------------------------------------------------------------------------------------------------------------------------------
private int MovePlayer(int dice_value)
{
currentPlayer.SetPosition(currentPlayer.GetPosition() + dice_value);
if (currentPlayer.GetPosition() > (squares.Count - 1))
{
currentPlayer.SetPosition(currentPlayer.GetPosition() % squares.Count());
currentPlayer.SetMoney(200);
}
return currentPlayer.GetPosition();
}
private void changeActivePlayer()
{
currentPlayerID += 1;
do
{
if (currentPlayerID >= players.Count())
{
currentPlayerID = 0;
}
currentPlayer = players[currentPlayerID];
} while (currentPlayer.IsBankrupt() == true);
}
//------------------------------------------------------------------------------------------------------------------------------------
// START/RESUME GAME
//------------------------------------------------------------------------------------------------------------------------------------
private void startGame()
{
createArrays();
currentPlayer = players[0];
CurrentSquare = squares[0];
if (players_table == null)
{
foreach (Player player in players)
{
SQLDatabase.DatabaseRow new_row = players_table.NewRow();
string new_id = players_table.GetNextID().ToString();
new_row["ID"] = new_id;
new_row["position"] = player.GetPosition().ToString();
new_row["money"] = player.GetMoney().ToString();
new_row["isInJail"] = player.IsInJail().ToString();
new_row["isBankrupt"] = player.IsBankrupt().ToString();
players_table.Insert(new_row);
}
}
if (gameinfo_table == null)
{
SQLDatabase.DatabaseRow new_row = gameinfo_table.NewRow();
new_row["ID"] = 1.ToString();
new_row["CurrentPlayerID"] = currentPlayer.GetID().ToString();
new_row["CurrentSquareID"] = CurrentSquare.GetID().ToString();
new_row["FreeParkingAmount"] = freeParkingAmount.ToString();
gameinfo_table.Insert(new_row);
}
writeToDatabase();
}
protected void StartButton_Click(object sender, EventArgs e)
{
startGame();
updateDisplay();
RollDiceButton.Enabled = true;
EndTurnButton.Enabled = true;
StartButton.Visible = false;
ResumeButton.Visible = false;
}
private void resumeGame()
{
readFromDatabase();
updateDisplay();
}
//------------------------------------------------------------------------------------------------------------------------------------
// READ/WRITE TO DATABASE
//------------------------------------------------------------------------------------------------------------------------------------
private void readFromDatabase()
{
createArrays();
for (int i = 0; i < 4; i++)
{
//players[i].SetID(Convert.ToInt32(players_table.GetRow(i)["ID"]));
players[i].SetPosition(Convert.ToInt32(players_table.GetRow(i)["position"]));
players[i].SetMoney(Convert.ToInt32(players_table.GetRow(i)["money"]));
players[i].SetInJail(Convert.ToBoolean(players_table.GetRow(i)["isInJail"]));
players[i].SetIsBankrupt(Convert.ToBoolean(players_table.GetRow(i)["isBankrupt"]));
}
currentPlayerID = Convert.ToInt32(gameinfo_table.GetRow(0)["CurrentPlayerID"]);
currentSquareID = Convert.ToInt32(gameinfo_table.GetRow(0)["CurrentSquareID"]);
freeParkingAmount = Convert.ToInt32(gameinfo_table.GetRow(0)["FreeParkingAmount"]);
currentPlayer = players[currentPlayerID];
CurrentSquare = squares[currentSquareID];
}
private void writeToDatabase()
{
foreach (Player player in players)
{
SQLDatabase.DatabaseRow prow = players_table.GetRow(player.GetID());
//prow["ID"] = player.GetID().ToString();
prow["position"] = player.GetPosition().ToString();
prow["money"] = player.GetMoney().ToString();
prow["isInJail"] = player.IsInJail().ToString();
prow["isBankrupt"] = player.IsBankrupt().ToString();
players_table.Update(prow);
}
SQLDatabase.DatabaseRow girow = gameinfo_table.GetRow(0);
girow["CurrentPlayerID"] = currentPlayerID.ToString();
girow["CurrentSquareID"] = CurrentSquare.GetID().ToString();
girow["FreeParkingAmount"] = freeParkingAmount.ToString();
}
//------------------------------------------------------------------------------------------------------------------------------------
// CREATE PLAYER AND SQUARE ARRAYS
//------------------------------------------------------------------------------------------------------------------------------------
private void createArrays()
{
for (int i = 0; i < 4; i++)
{
Player player = new Player(i);
players.Add(player);
}
Square square0 = new Square(0, 0, 0, "Go", "go");
Square square1 = new Square(1, 60, 2, "Old Kent Road", "prop");
Square square2 = new Square(2, 0, 0, "Community Chest", "comm");
Square square3 = new Square(3, 60, 4, "Whitechapel Road", "prop");
Square square4 = new Square(4, 200, 0, "Income Tax", "tax");
Square square5 = new Square(5, 200, 25, "Kings Cross Station", "prop");
Square square6 = new Square(6, 100, 6, "The Angel Islington", "prop");
Square square7 = new Square(7, 0, 0, "Chance", "chance");
Square square8 = new Square(8, 100, 6, "Euston Road", "prop");
Square square9 = new Square(9, 120, 8, "Pentonville Road", "prop");
Square square10 = new Square(10, 0, 0, "Visiting Jail", "other");
Square square11 = new Square(11, 140, 10, "Pall Mall", "prop");
Square square12 = new Square(12, 150, 12, "Electric Company", "prop");
Square square13 = new Square(13, 140, 10, "Whitehall", "prop");
Square square14 = new Square(14, 160, 12, "Northumberland Avenue", "prop");
Square square15 = new Square(15, 200, 25, "Marylebone Station", "prop");
Square square16 = new Square(16, 180, 14, "Bow Street", "prop");
Square square17 = new Square(17, 0, 0, "Community Chest", "comm");
Square square18 = new Square(18, 180, 14, "Marlborough Street", "prop");
Square square19 = new Square(19, 200, 16, "Vine Street", "prop");
Square square20 = new Square(20, 0, 0, "Free Parking", "freep");
Square square21 = new Square(21, 220, 18, "Strand", "prop");
Square square22 = new Square(22, 0, 0, "Chance", "chance");
Square square23 = new Square(23, 220, 18, "Fleet Street", "prop");
Square square24 = new Square(24, 240, 20, "Trafalgar Square", "prop");
Square square25 = new Square(25, 200, 25, "Fenchurch Street Station", "prop");
Square square26 = new Square(26, 260, 22, "Leicester Square", "prop");
Square square27 = new Square(27, 260, 22, "Coventry Street", "prop");
Square square28 = new Square(28, 150, 12, "Water Works", "prop");
Square square29 = new Square(29, 280, 22, "Piccadilly", "prop");
Square square30 = new Square(30, 0, 0, "Jail", "jail");
Square square31 = new Square(31, 300, 26, "Regent Street", "prop");
Square square32 = new Square(32, 300, 26, "Oxford Street", "prop");
Square square33 = new Square(33, 0, 0, "Community Chest", "comm");
Square square34 = new Square(34, 320, 28, "Bond Street", "prop");
Square square35 = new Square(35, 200, 25, "Liverpool Street Station", "prop");
Square square36 = new Square(36, 0, 0, "Chance", "chance");
Square square37 = new Square(37, 350, 35, "Park Lane", "prop");
Square square38 = new Square(38, 100, 0, "Super Tax", "tax");
Square square39 = new Square(39, 400, 50, "Mayfair", "prop");
squares.Add(square0);
squares.Add(square1);
squares.Add(square2);
squares.Add(square3);
squares.Add(square4);
squares.Add(square5);
squares.Add(square6);
squares.Add(square7);
squares.Add(square8);
squares.Add(square9);
squares.Add(square10);
squares.Add(square11);
squares.Add(square12);
squares.Add(square13);
squares.Add(square14);
squares.Add(square15);
squares.Add(square16);
squares.Add(square17);
squares.Add(square18);
squares.Add(square19);
squares.Add(square20);
squares.Add(square21);
squares.Add(square22);
squares.Add(square23);
squares.Add(square24);
squares.Add(square25);
squares.Add(square26);
squares.Add(square27);
squares.Add(square28);
squares.Add(square29);
squares.Add(square30);
squares.Add(square31);
squares.Add(square32);
squares.Add(square33);
squares.Add(square34);
squares.Add(square35);
squares.Add(square36);
squares.Add(square37);
squares.Add(square38);
squares.Add(square39);
}
}
}
As far as I know the database code I've got works fine as I can resume a game and it will set the player position to be the square they were at before. But for some reason when starting the game it is constantly player 2's turn, and the changeActivePlayer() doesn't seem do anything to help this. I stepped through the code line by line and after clicking the EndTurnButton the playerID had changed but when it came to getting the values from the database it was back to player 2's ID. I'm also not sure why it defaults to player 2, seeing as when I call the start game function I set the current player to players[0] so surely it should be player 1? Any help on this would be appreciated.

How to add additionalIcons to the tile in a Band

I am developing Microsoft Band2 Apps, I want to add Additional icons to my app tile in a band, like setting tile in Band2. I followed the below code to add Additional icons to the tile
Guid pageguid = Guid.NewGuid();
var panel = new ScrollFlowPanel
{
Rect = new PageRect(0, 0, 260, 128),
};
panel.Elements.Add(new FlowPanel
{
Rect = new PageRect(0, 0, 32, 32),
HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center,
});
panel.Elements.Add(new Icon
{
HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center,
Rect= new PageRect(0, 0, 32, 32),
ColorSource= ElementColorSource.BandHighlight,
});
var layout = new PageLayout(panel);
BandTile tile = new BandTile(tileGuid)
{
Name = "EmergencyHelp ",
TileIcon = await LoadIcon("ms-appx:///Assets/User that is member of security group.png"),
SmallIcon = await LoadIcon("ms-appx:///Assets/User that is member of security groupSmall.png"),
};
int firstIconIndex = tile.AdditionalIcons.Count + 2; // First 2 are used by the Tile itself
tile.AdditionalIcons.Add(await LoadIconMethod(AdjustUriMethod("ms-appx:///Assets/User that is member of security groupSmall.png")));
pageLayoutData.ById<IconData>(3).IconIndex = (ushort)(firstIconIndex + 0);
tile.PageLayouts.Add(layout);
if (tile.TileId != null)
{
await client.TileManager.RemoveTileAsync(tile.TileId);
}
await client.TileManager.AddTileAsync(tile);
await client.TileManager.SetPagesAsync(
tileGuid,
new PageData(pageguid, 0, new TextButtonData(1, "Emergency")));
I am getting the exception as shown in below figure,

how to control Javafx scalafx FXyz 3D shapes

I have the following test code where I have a ClothMesh (from FXyz lib) that I
can drag, rotate and drag my circle handles. All works well, FXyz is great. Now I want to use SegmentedSphereMesh, it mostly work except that my circle handles are 2D and not wrapped around the sphere. I know the possible problems mixing 2D and 3D. However, it is so close to working; how can I make my handles work with the sphere, or what would be another way to do the same function.
Note, I do not want to control the shape/mesh by moving the camera around.
import org.fxyz.shapes.complex.cloth.ClothMesh
import org.fxyz.shapes.primitives.SegmentedSphereMesh
import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.beans.property.DoubleProperty
import scalafx.collections.ObservableFloatArray
import scalafx.scene.image.Image
import scalafx.scene.input.{MouseButton, MouseEvent}
import scalafx.scene.paint.PhongMaterial
import scalafx.scene.shape._
import scalafx.scene.transform.Rotate
import scalafx.scene._
import scalafx.scene.paint.Color
/**
* left mouse to drag the meshView and also to drag the handles
* right mouse drag + ctrl to rotate about X axis
* right mouse drag + alt to rotate about Y axis
* right mouse drag + shift to rotate about Z axis
*/
object ClothTest2 extends JFXApp {
private var dx = 0.0
private var dy = 0.0
stage = new PrimaryStage {
scene = new Scene(600, 600, true, SceneAntialiasing.Balanced) {
fill = Color.LightGray
val testImg = "https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png"
val img = new Image(testImg, 400, 400, false, true)
val meshView = new SegmentedSphereMesh(20, 4, 2, 200d)
// val meshView = new ClothMesh(4, 4, 200, 200, 0.5, 0.5, 1.0)
meshView.setDrawMode(DrawMode.Fill)
meshView.setCullFace(CullFace.None)
meshView.style = "-fx-background-color: #00000000"
meshView.setMaterial(new PhongMaterial(Color.White, img, null, null, null))
val controller = new MeshController(meshView.getMesh().asInstanceOf[javafx.scene.shape.TriangleMesh].points)
val viewGroup = new Group(meshView, controller)
root = new Group(new AmbientLight(Color.White), viewGroup) { translateX = 70; translateY = 70 }
camera = new PerspectiveCamera(true) {
nearClip = 0.0
farClip = 100000.0
fieldOfView = 42
verticalFieldOfView = true
translateZ = -900
}
val rotHandler = new RotHandler(viewGroup)
onMouseDragged = (event: MouseEvent) => {
rotHandler.onMouseDragged(event)
if (event.button == MouseButton.PRIMARY) {
viewGroup.layoutX = event.sceneX + dx
viewGroup.layoutY = event.sceneY + dy
event.consume()
}
}
onMousePressed = (event: MouseEvent) => {
rotHandler.onMousePressed(event)
dx = viewGroup.layoutX.value - event.sceneX
dy = viewGroup.layoutY.value - event.sceneY
event.consume()
}
}
}
}
class CircleHandle(color: Color) extends Circle {
radius = 8
var dx = 0.0
var dy = 0.0
fill <== when(hover) choose Color.Red.deriveColor(1, 1, 1, 0.4) otherwise color.deriveColor(1, 1, 1, 0.4)
strokeWidth <== when(hover) choose 3 otherwise 2
stroke = color
onMousePressed = (event: MouseEvent) => {
dx = centerX.value - event.x
dy = centerY.value - event.y
event.consume()
}
onMouseDragged = (event: MouseEvent) => {
centerX = event.x + dx
centerY = event.y + dy
event.consume()
}
}
class MeshController(thePoints: ObservableFloatArray) extends Group {
children = for (i <- 0 until thePoints.size by 3) yield new CircleHandle(Color.Yellow) {
centerX() = thePoints.get(i)
centerX.onChange { (obs, oldVal, newVal) => thePoints.set(i, newVal.floatValue()) }
centerY() = thePoints.get(i + 1)
centerY.onChange { (obs, oldVal, newVal) => thePoints.set(i + 1, newVal.floatValue()) }
}
}
class RotHandler(val viewer: Group) {
private val angleX = DoubleProperty(0)
private val angleY = DoubleProperty(0)
private val angleZ = DoubleProperty(0)
private var anchorX = 0d
private var anchorY = 0d
private val rotX = new Rotate { angle <== angleX; axis = Rotate.XAxis }
private val rotY = new Rotate { angle <== angleY; axis = Rotate.YAxis }
private val rotZ = new Rotate { angle <== angleZ; axis = Rotate.ZAxis }
viewer.transforms = Seq(rotX, rotY, rotZ)
def onMousePressed(event: MouseEvent) = {
anchorX = event.sceneX
anchorY = event.sceneY
event.consume()
}
def onMouseDragged(event: MouseEvent) = {
// right mouse only
if (event.button == MouseButton.SECONDARY) {
event match {
// rotation about the Y axis, dragging the mouse in the x direction
case ev if ev.altDown => angleY() = anchorX - event.sceneX
// rotation about the X axis, dragging the mouse in the y direction
case ev if ev.controlDown => angleX() = anchorY - event.sceneY
// rotation about the Z axis, dragging the mouse in the x direction
case ev if ev.shiftDown => angleZ() = anchorX - event.sceneX
case _ => // ignore everything else
}
}
event.consume()
}
}

Resources