A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AlmasB/FXGL/commit/a3e5599eb below:

Added draft skybox implementation · AlmasB/FXGL@a3e5599 · GitHub

File tree Expand file treeCollapse file tree 1 file changed

+127

-0

lines changed

Filter options

Expand file treeCollapse file tree 1 file changed

+127

-0

lines changed Original file line number Diff line number Diff line change

@@ -0,0 +1,127 @@

1 +

/*

2 +

* FXGL - JavaFX Game Library. The MIT License (MIT).

3 +

* Copyright (c) AlmasB (almaslvl@gmail.com).

4 +

* See LICENSE for details.

5 +

*/

6 + 7 +

package com.almasb.fxgl.scene3d

8 + 9 +

import com.almasb.fxgl.dsl.image

10 +

import com.almasb.fxgl.texture.getDummyImage

11 +

import javafx.scene.Group

12 +

import javafx.scene.Node

13 +

import javafx.scene.image.Image

14 +

import javafx.scene.image.ImageView

15 +

import javafx.scene.transform.Rotate

16 + 17 +

/**

18 +

*

19 +

* @author Almas Baimagambetov (almaslvl@gmail.com)

20 +

*/

21 +

class SkyboxBuilder(val width: Int,

22 +

val height: Int) {

23 + 24 +

private var front: Image = getDummyImage()

25 +

private var back: Image = getDummyImage()

26 +

private var left: Image = getDummyImage()

27 +

private var right: Image = getDummyImage()

28 +

private var top: Image = getDummyImage()

29 +

private var bot: Image = getDummyImage()

30 + 31 +

fun front(imageName: String) = this.also {

32 +

front = image(imageName)

33 +

}

34 + 35 +

fun back(imageName: String) = this.also {

36 +

back = image(imageName)

37 +

}

38 + 39 +

fun left(imageName: String) = this.also {

40 +

left = image(imageName)

41 +

}

42 + 43 +

fun right(imageName: String) = this.also {

44 +

right = image(imageName)

45 +

}

46 + 47 +

fun top(imageName: String) = this.also {

48 +

top = image(imageName)

49 +

}

50 + 51 +

fun bot(imageName: String) = this.also {

52 +

bot = image(imageName)

53 +

}

54 + 55 +

fun build(): Skybox {

56 +

return Skybox(

57 +

width,

58 +

height,

59 +

front,

60 +

back,

61 +

left,

62 +

right,

63 +

top,

64 +

bot

65 +

)

66 +

}

67 +

}

68 + 69 +

class Skybox(

70 +

val width: Int,

71 +

val height: Int,

72 +

val front: Image,

73 +

val back: Image,

74 +

val left: Image,

75 +

val right: Image,

76 +

val top: Image,

77 +

val bot: Image

78 +

) : Group() {

79 + 80 +

init {

81 +

// TODO: use both width and height

82 +

// TODO: why 32?

83 +

val size = width * 32

84 +

val t = size / 2.0

85 + 86 +

children.addAll(

87 +

toView(front).also {

88 +

it.translateZ = t

89 +

},

90 +

toView(back).also {

91 +

it.translateZ = -t

92 +

it.rotationAxis = Rotate.Y_AXIS

93 +

it.rotate = 180.0

94 +

},

95 +

toView(left).also {

96 +

it.translateX = -t

97 +

it.rotationAxis = Rotate.Y_AXIS

98 +

it.rotate = -90.0

99 +

},

100 +

toView(right).also {

101 +

it.translateX = t

102 +

it.rotationAxis = Rotate.Y_AXIS

103 +

it.rotate = 90.0

104 +

},

105 +

toView(top).also {

106 +

it.translateY = -t

107 +

it.rotationAxis = Rotate.X_AXIS

108 +

it.rotate = 90.0

109 +

},

110 +

toView(bot).also {

111 +

it.translateY = t

112 +

it.rotationAxis = Rotate.X_AXIS

113 +

it.rotate = -90.0

114 +

}

115 +

)

116 +

}

117 + 118 +

private fun toView(image: Image): Node {

119 +

val view = ImageView(image)

120 + 121 +

// TODO: scale differently?

122 +

view.isSmooth = true

123 +

view.scaleX = 32.0

124 +

view.scaleY = 32.0

125 +

return view

126 +

}

127 +

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4