Added 3D wind arrow and it also rotates #story[1306]

main
Fan-Wu Yang 8 years ago
parent d280c0bdae
commit 45ba3ae6ac

@ -61,6 +61,7 @@ public class RaceViewController extends Controller {
private boolean isTutorial = false;
private String keyToPress;
private View3D view3D;
private WindCompass windCompass;
private ObservableList<Subject3D> viewSubjects;
private ResizableRaceCanvas raceCanvas;
private boolean mapToggle = true;
@ -268,6 +269,9 @@ public class RaceViewController extends Controller {
view3D.addPointLight(pointLight);
canvasBase.add(view3D, 0, 0);
windCompass = new WindCompass(view3D, this.raceState.windProperty());
arrowPane.getChildren().add(windCompass);
// Set up projection from GPS to view
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450);

@ -16,9 +16,12 @@ import java.net.URL;
public class Assets3D {
public static MeshView[] sails;
public static Subject3D windArrow;
public static Subject3D compass;
public static void loadAssets(){
loadSails();
loadWindArrow();
}
private static void loadSails(){
@ -39,15 +42,26 @@ public class Assets3D {
}
public static Shape3D getBoat(){
X3dModelImporter x3dModelImporter = new X3dModelImporter();
String path = "assets/V1.3 Complete Boat without Sail and Rotated.x3d";
return loadX3d(path);
}
private static void loadWindArrow(){
String compassPath = "assets/wind_compass.x3d";
compass = new Annotation3D(loadX3d(compassPath));
String arrowPath = "assets/wind_arrow.x3d";
windArrow = new Annotation3D(loadX3d(arrowPath));
}
private static Shape3D loadX3d(String path){
X3dModelImporter x3dModelImporter = new X3dModelImporter();
URL asset = Assets3D.class.getClassLoader().getResource(path);
x3dModelImporter.read(asset);
if (x3dModelImporter.getImport().length > 0) {
//if (x3dModelImporter.getImport()[0] instanceof MeshView) {
Group g = (Group)((Group)((Group) x3dModelImporter.getImport()[0]).getChildren().get(0)).getChildren().get(0);
Shape3D boat = (Shape3D)g.getChildren().get(0);
return boat;
Shape3D shape = (Shape3D)g.getChildren().get(0);
return shape;
/*} else {
System.err.println("Boat is not a Mesh View 0.0");
}*/

@ -288,6 +288,10 @@ public class View3D extends Pane {
this.yaw.setAngle(yaw);
}
public double getYaw(){
return this.yaw.getAngle();
}
/**
* Set elevation of camera
* @param pitch in degrees
@ -296,6 +300,10 @@ public class View3D extends Pane {
this.pitch.setAngle(-pitch);
}
public double getPitch(){
return this.pitch.getAngle();
}
public void addAmbientLight(AmbientLight ambientLight) {
this.world.getChildren().add(ambientLight);
}

@ -0,0 +1,50 @@
package visualiser.layout;
import javafx.animation.AnimationTimer;
import javafx.beans.property.Property;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import shared.model.Wind;
/**
* Created by Gondr on 25/09/2017.
*/
public class WindCompass extends View3D {
Subject3D compass;
Subject3D windArrow;
View3D view3D;
Property<Wind> wind;
AnimationTimer followView3D = new AnimationTimer() {
@Override
public void handle(long now) {
setYaw(180+ view3D.getYaw());
setPitch(30 - view3D.getPitch());
windArrow.setHeading(wind.getValue().getWindDirection().degrees());
}
};
public WindCompass(View3D view3D, Property<Wind> wind){
super();
this.wind = wind;
this.view3D = view3D;
this.followView3D.start();
ObservableList<Subject3D> subjects = FXCollections.observableArrayList();
this.setItems(subjects);
compass = Assets3D.compass;
windArrow = Assets3D.windArrow;
subjects.addAll(compass, windArrow);
this.setDistance(30);
this.setPitch(90);
this.setYaw(180);
}
public void setHeading(double heading){
windArrow.setHeading(heading);
}
public void setCompassPitch(double pitch){
setPitch(90d + pitch);
}
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D version="3.0" profile="Immersive" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd">
<head>
<meta name="filename" content="compass.x3d" />
<meta name="generator" content="Blender 2.77 (sub 0)" />
</head>
<Scene>
<NavigationInfo headlight="true"
visibilityLimit="0.0"
type='"EXAMINE", "ANY"'
avatarSize="0.25, 1.75, 0.75"
/>
<Background DEF="WO_World"
groundColor="0.051 0.051 0.051"
skyColor="0.051 0.051 0.051"
/>
<Transform DEF="Cube_001_TRANSFORM"
translation="0.000000 0.000000 0.000000"
scale="1.000000 1.000000 1.000000"
rotation="0.000000 0.707107 0.707107 3.141593"
>
<Transform DEF="Cube_001_ifs_TRANSFORM"
translation="0.000000 0.000000 0.000000"
scale="1.000000 1.000000 1.000000"
rotation="1.000000 0.000000 0.000000 0.000000"
>
<Group DEF="group_ME_Cube_001">
<Shape>
<Appearance>
<ImageTexture DEF="IM_Material_002_Diffuse_Color"
url='"." ""'
/>
<TextureTransform
translation="0.000000 0.000000"
scale="1.000000 1.000000"
rotation="0.000000"
/>
<Material DEF="MA_Material_002"
diffuseColor="0.800 0.800 0.800"
specularColor="0.401 0.401 0.401"
emissiveColor="0.000 0.000 0.000"
ambientIntensity="0.333"
shininess="0.098"
transparency="0.0"
/>
</Appearance>
<IndexedFaceSet solid="true"
texCoordIndex="0 1 2 -1 3 4 5 -1 6 7 8 -1 9 10 11 -1 12 13 14 -1 15 16 17 -1 18 19 20 -1 21 22 23 -1 24 25 26 -1 27 28 29 -1 30 31 32 -1 33 34 35 -1 36 37 38 -1 39 40 41 -1 42 43 44 -1 45 46 47 -1 48 49 50 51 -1 52 53 54 55 -1 56 57 58 59 -1 60 61 62 63 -1 64 65 66 67 -1 68 69 70 71 -1 72 73 74 75 -1 76 77 78 79 -1 80 81 82 83 -1 84 85 86 87 -1 88 89 90 -1 91 92 93 -1 94 95 96 -1 97 98 99 -1 100 101 102 -1 103 104 105 -1 106 107 108 -1 109 110 111 -1 112 113 114 -1 115 116 117 -1 118 119 120 -1 121 122 123 -1 124 125 126 -1 127 128 129 -1 130 131 132 -1 133 134 135 -1 136 137 138 -1 139 140 141 -1 142 143 144 -1 145 146 147 -1 148 149 150 -1 151 152 153 -1 154 155 156 -1 157 158 159 -1 160 161 162 -1 163 164 165 -1 166 167 168 -1 169 170 171 -1 172 173 174 -1 175 176 177 -1 178 179 180 -1 181 182 183 -1 "
coordIndex="5 4 3 -1 5 3 7 -1 7 3 2 -1 2 1 0 -1 2 0 9 -1 5 7 6 -1 8 7 2 -1 8 2 9 -1 15 13 14 -1 15 17 13 -1 17 12 13 -1 12 10 11 -1 12 19 10 -1 15 16 17 -1 18 12 17 -1 18 19 12 -1 3 4 14 13 -1 8 9 19 18 -1 5 6 16 15 -1 0 1 11 10 -1 9 0 10 19 -1 6 7 17 16 -1 4 5 15 14 -1 2 3 13 12 -1 1 2 12 11 -1 7 8 18 17 -1 28 22 34 -1 34 21 24 -1 21 34 20 -1 34 22 20 -1 28 35 22 -1 22 35 20 -1 20 35 21 -1 21 35 24 -1 33 34 26 -1 34 24 25 -1 25 23 34 -1 34 23 26 -1 33 26 35 -1 26 23 35 -1 23 25 35 -1 25 24 35 -1 28 34 30 -1 34 32 29 -1 29 27 34 -1 34 27 30 -1 28 30 35 -1 30 27 35 -1 27 29 35 -1 29 32 35 -1 33 37 34 -1 34 36 32 -1 36 34 31 -1 34 37 31 -1 33 35 37 -1 37 35 31 -1 31 35 36 -1 36 35 32 -1 "
>
<Coordinate DEF="coords_ME_Cube_001"
point="0.531748 6.874471 -0.300000 0.376386 6.874471 -0.300000 0.376386 5.982826 -0.300000 -0.403803 6.874471 -0.300000 -0.535524 6.874471 -0.300000 -0.535524 5.722763 -0.300000 -0.380161 5.722763 -0.300000 -0.380161 6.609342 -0.300000 0.389895 5.722763 -0.300000 0.531748 5.722763 -0.300000 0.531748 6.874471 0.300000 0.376386 6.874471 0.300000 0.376386 5.982826 0.300000 -0.403803 6.874471 0.300000 -0.535524 6.874471 0.300000 -0.535524 5.722763 0.300000 -0.380161 5.722763 0.300000 -0.380161 6.609342 0.300000 0.389895 5.722763 0.300000 0.531748 5.722763 0.300000 2.633970 2.767104 0.312926 0.569966 1.211178 0.287543 1.211178 0.569966 0.287543 -2.633970 2.767104 0.312926 0.000000 5.000000 0.000000 -0.569966 1.211178 0.287543 -1.211178 0.569966 0.287543 2.633970 -2.767104 0.312926 5.000000 0.000000 0.000000 0.569966 -1.211178 0.287543 1.211178 -0.569966 0.287543 -2.633970 -2.767104 0.312926 0.000000 -5.000000 0.000000 -5.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 -1.000000 -0.569966 -1.211178 0.287543 -1.211178 -0.569966 0.287543 "
/>
<TextureCoordinate point="0.1067 0.9142 0.1067 0.7995 0.0936 0.7995 0.1067 0.9142 0.0936 0.7995 0.0913 0.8259 0.0913 0.8259 0.0936 0.7995 0.0160 0.8883 0.0160 0.8883 0.0160 0.7995 0.0005 0.7995 0.0160 0.8883 0.0005 0.7995 0.0005 0.9142 0.1067 0.9142 0.0913 0.8259 0.0913 0.9142 0.0146 0.9142 0.0913 0.8259 0.0160 0.8883 0.0146 0.9142 0.0160 0.8883 0.0005 0.9142 0.2140 0.9142 0.2008 0.7995 0.2140 0.7995 0.2140 0.9142 0.1985 0.8259 0.2008 0.7995 0.1985 0.8259 0.1232 0.8883 0.2008 0.7995 0.1232 0.8883 0.1077 0.7995 0.1232 0.7995 0.1232 0.8883 0.1077 0.9142 0.1077 0.7995 0.2140 0.9142 0.1985 0.9142 0.1985 0.8259 0.1218 0.9142 0.1232 0.8883 0.1985 0.8259 0.1218 0.9142 0.1077 0.9142 0.1232 0.8883 0.4359 0.5534 0.4490 0.5534 0.4490 0.4937 0.4359 0.4937 0.7841 0.8195 0.7841 0.8336 0.7244 0.8336 0.7244 0.8195 0.4349 0.5534 0.4195 0.5534 0.4195 0.4937 0.4349 0.4937 0.7841 0.8185 0.7841 0.8030 0.7244 0.8030 0.7244 0.8185 0.3296 0.8593 0.2149 0.8593 0.2149 0.7995 0.3296 0.7995 0.7183 0.8030 0.7183 0.8913 0.6586 0.8913 0.6586 0.8030 0.4532 0.8627 0.5679 0.8627 0.5679 0.8030 0.4532 0.8030 0.6576 0.8627 0.5689 0.8627 0.5689 0.8030 0.6576 0.8030 0.5689 0.8627 0.6576 0.8627 0.6576 0.8030 0.5689 0.8030 0.7183 0.8913 0.7183 0.8030 0.6586 0.8030 0.6586 0.8913 0.3391 0.4927 0.2269 0.1282 0.2650 0.0005 0.3782 0.0005 0.4523 0.1113 0.4523 0.4927 0.9561 0.6355 0.9981 0.5091 0.9981 0.8894 0.9135 0.3808 0.8653 0.2566 0.9135 0.0005 0.5553 0.5081 0.5553 0.0005 0.4532 0.1439 0.2778 0.5999 0.3693 0.4937 0.3693 0.7986 0.6330 0.8020 0.6330 0.5091 0.5436 0.6170 0.7623 0.1439 0.8643 0.0005 0.8643 0.5081 0.1127 0.0005 0.0387 0.4927 0.0005 0.3650 0.3782 0.0005 0.4523 0.4927 0.3401 0.1282 0.9575 0.2543 0.9995 0.0005 0.9995 0.3808 0.8630 0.5091 0.8630 0.8894 0.8147 0.6333 0.6583 0.0005 0.5563 0.3647 0.6583 0.5081 0.1854 0.5999 0.2769 0.7986 0.2769 0.4937 0.7234 0.5091 0.6340 0.6941 0.7234 0.8020 0.7623 0.1439 0.8643 0.5081 0.8643 0.0005 0.3391 0.4927 0.2650 0.0005 0.3391 0.1113 0.1518 0.0005 0.2259 0.4927 0.1137 0.1282 0.9145 0.2543 0.9565 0.0005 0.9565 0.3808 0.9121 0.5091 0.9121 0.8894 0.8639 0.6333 0.5553 0.5081 0.4532 0.1439 0.5553 0.0005 0.0929 0.6924 0.1844 0.4937 0.1844 0.7986 0.5426 0.8020 0.4532 0.6170 0.5426 0.5091 0.6593 0.3647 0.7613 0.0005 0.7613 0.5081 0.1127 0.0005 0.1127 0.3819 0.0387 0.4927 0.1518 0.0005 0.2259 0.1113 0.2259 0.4927 0.9131 0.6355 0.9551 0.5091 0.9551 0.8894 0.4185 0.8740 0.3703 0.7497 0.4185 0.4937 0.6583 0.0005 0.6583 0.5081 0.5563 0.3647 0.0005 0.6924 0.0920 0.7986 0.0920 0.4937 0.8138 0.5091 0.8138 0.8020 0.7244 0.6941 0.6593 0.3647 0.7613 0.5081 0.7613 0.0005 " />
</IndexedFaceSet>
</Shape>
</Group>
</Transform>
</Transform>
</Scene>
</X3D>
Loading…
Cancel
Save