Properly center StreamContainer at center of camera.
parent
c690f0f152
commit
ed29cc1288
|
@ -149,14 +149,28 @@ public class Game : Spatial
|
|||
|
||||
public void UpdateCurrentTile()
|
||||
{
|
||||
Transform playerTransform = _player.Transform;
|
||||
Vector3 playerCoord = playerTransform.origin;
|
||||
_currentTile = _hexGrid.GetHexAt(new Vector2(playerCoord.x, playerCoord.z));
|
||||
// cast a ray from the camera to center
|
||||
Vector3 cameraNormal = _camera.ProjectRayNormal(_camera.GetViewport().Size * 0.5f);
|
||||
Vector3 cameraPosition = _camera.ProjectRayOrigin(_camera.GetViewport().Size * 0.5f);
|
||||
Vector3 cameraDir = cameraNormal - cameraPosition;
|
||||
|
||||
_tileLabel.Text = playerTransform.ToString();
|
||||
Vector3 centerCoord;
|
||||
|
||||
if (Mathf.Abs(cameraDir.y) > Globals.EpsPosition)
|
||||
{
|
||||
centerCoord = cameraPosition + cameraNormal * (-cameraPosition.y / cameraNormal.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
centerCoord = _camera.GlobalTranslation;
|
||||
centerCoord.y = 0;
|
||||
}
|
||||
|
||||
|
||||
_currentTile = _hexGrid.GetHexAt(new Vector2(centerCoord.x, centerCoord.z));
|
||||
|
||||
_tileLabel.Text = centerCoord.ToString();
|
||||
_tileOffsetLabel.Text = _currentTile.OffsetCoords.ToString();
|
||||
|
||||
_player.Transform = playerTransform;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -201,31 +201,9 @@ margin_bottom = 258.0
|
|||
alignment = 2
|
||||
script = ExtResource( 12 )
|
||||
|
||||
[node name="WorldTextureRect" type="TextureRect" parent="Generator Container/WorldGeneratorContainer"]
|
||||
margin_right = 100.0
|
||||
margin_bottom = 100.0
|
||||
rect_min_size = Vector2( 100, 100 )
|
||||
stretch_mode = 1
|
||||
flip_v = true
|
||||
|
||||
[node name="HeightTextureRect" type="TextureRect" parent="Generator Container/WorldGeneratorContainer"]
|
||||
margin_top = 104.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 204.0
|
||||
rect_min_size = Vector2( 100, 100 )
|
||||
stretch_mode = 1
|
||||
flip_v = true
|
||||
|
||||
[node name="WorldGenerateButton" type="Button" parent="Generator Container/WorldGeneratorContainer"]
|
||||
margin_top = 208.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 228.0
|
||||
text = "Generate"
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Generator Container/WorldGeneratorContainer"]
|
||||
margin_top = 232.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 248.0
|
||||
margin_bottom = 16.0
|
||||
|
||||
[node name="WorldSizeSlider" type="HSlider" parent="Generator Container/WorldGeneratorContainer/HBoxContainer"]
|
||||
margin_right = 88.0
|
||||
|
@ -242,10 +220,32 @@ margin_right = 100.0
|
|||
margin_bottom = 15.0
|
||||
text = "4"
|
||||
|
||||
[node name="WorldGenerateButton" type="Button" parent="Generator Container/WorldGeneratorContainer"]
|
||||
margin_top = 20.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 40.0
|
||||
text = "Generate"
|
||||
|
||||
[node name="WorldTextureRect" type="TextureRect" parent="Generator Container/WorldGeneratorContainer"]
|
||||
margin_top = 44.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 144.0
|
||||
rect_min_size = Vector2( 100, 100 )
|
||||
stretch_mode = 1
|
||||
flip_v = true
|
||||
|
||||
[node name="HeightTextureRect" type="TextureRect" parent="Generator Container/WorldGeneratorContainer"]
|
||||
margin_top = 148.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 248.0
|
||||
rect_min_size = Vector2( 100, 100 )
|
||||
stretch_mode = 1
|
||||
flip_v = true
|
||||
|
||||
[node name="StreamContainer" type="Spatial" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 2.98023e-08, 0, -2.98023e-08, 1, 0, 0, -4.76837e-07 )
|
||||
script = ExtResource( 1 )
|
||||
Dimensions = Vector2( 30, 30 )
|
||||
Dimensions = Vector2( 35, 30 )
|
||||
World = NodePath("../TileWorld")
|
||||
|
||||
[node name="ActiveTiles" type="Spatial" parent="StreamContainer"]
|
||||
|
@ -264,7 +264,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
|
|||
shape = SubResource( 9 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, 1.7053e-13, 10.6428, 6.65615 )
|
||||
transform = Transform( 1, 0, 0, 0, 0.60042, 0.799685, 0, -0.799685, 0.60042, -4.76837e-07, 8.3759, 5.70105 )
|
||||
current = true
|
||||
fov = 60.0
|
||||
script = ExtResource( 10 )
|
||||
|
|
Loading…
Reference in New Issue