光Spot类是JavaFX的一部分。光Spot类用于创建一个聚光灯,该聚光灯在3D空间中具有光的方向向量、焦点和颜色的可配置值。光Spot类继承 光指向 班
null
类的构造函数:
- Spot() :使用默认值创建聚光灯
- 斑点(双x,双y,双z,双s,c色) :创建具有指定值x、y、z、镜面反射分量和灯光颜色的聚光灯
常用方法:
方法 | 解释 |
---|---|
getPointsAtX() | 返回光的方向向量的x坐标。 |
getPointsAtY() | 返回灯光方向向量的y坐标。 |
getPointsAtZ() | 返回光的方向向量的z坐标。 |
GetSpeculareComponent() | 返回SpeculareComponent的值。 |
设定点SATX(双v) | 设置灯光方向向量的x坐标值。 |
设定值(双v) | 设置灯光方向向量的y坐标值。 |
设定点卫星(双v) | 设置灯光方向向量的z坐标值。 |
SETSpeculareComponent(双v) | 设置镜面反射组件的值。 |
下面的程序说明了光线的使用。现场课程:
- 创建聚光灯并将其添加到矩形的Java程序: 在这个程序中,我们将创建一个名为 长方形 具有指定的高度和宽度。我们还将创建一个 光斑点物体 命名的 光 .我们将使用 setX() , 塞蒂() 和 setZ() 作用现在创建一个照明对象,并使用 setLight() 作用我们将为矩形设置灯光效果,并将其添加到场景中,将场景添加到舞台中,然后调用show函数来显示结果。
// Java Program to create a Spot light
// and add it to a rectangle
import
javafx.application.Application;
import
javafx.scene.Scene;
import
javafx.scene.shape.Rectangle;
import
javafx.scene.control.*;
import
javafx.stage.Stage;
import
javafx.scene.Group;
import
javafx.scene.effect.Light.*;
import
javafx.scene.effect.*;
import
javafx.scene.paint.Color;
public
class
Spot_1
extends
Application {
// launch the application
public
void
start(Stage stage)
{
// set title for the stage
stage.setTitle(
"creating Light.Spot"
);
// create Spot Light object
Light.Spot light =
new
Light.Spot();
// set coordinates
light.setX(
100
);
light.setY(
100
);
light.setZ(
100
);
// create a lighting
Lighting lighting =
new
Lighting();
// set Light of lighting
lighting.setLight(light);
// create a rectangle
Rectangle rect =
new
Rectangle(
250
,
250
);
// set fill
rect.setFill(Color.WHITE);
// set effect
rect.setEffect(lighting);
// create a Group
Group group =
new
Group(rect);
// create a scene
Scene scene =
new
Scene(group,
500
,
300
);
// set the scene
stage.setScene(scene);
stage.show();
}
// Main Method
public
static
void
main(String args[])
{
// launch the application
launch(args);
}
}
输出:
- Java程序创建聚光灯并将其添加到矩形中,并设置灯光方向向量和灯光颜色的坐标: 在这个程序中,我们将创建一个名为 长方形 具有指定的高度和宽度。我们还将创建一个 光斑点物体 命名的 光 .我们将使用 setX() , 塞蒂() 和 setZ() 作用光的方向向量的坐标是使用 设定点SATX() , 设定点状态() 和 设定点SATX() ,并使用指定颜色的值 setColor() 函数现在创建一个照明对象,并使用 setLight() 作用我们将为矩形设置灯光效果,并将其添加到场景中,将场景添加到舞台中,然后调用show函数来显示结果。
// Java Program to create a Spot light
// and add it to a rectangle and set the
// coordinates of direction vector of
// light and color of light
import
javafx.application.Application;
import
javafx.scene.Scene;
import
javafx.scene.shape.Rectangle;
import
javafx.scene.control.*;
import
javafx.stage.Stage;
import
javafx.scene.Group;
import
javafx.scene.effect.Light.*;
import
javafx.scene.effect.*;
import
javafx.scene.paint.Color;
public
class
Spot_2
extends
Application {
// launch the application
public
void
start(Stage stage)
{
// set title for the stage
stage.setTitle(
"creating Light.Spot"
);
// create Spot Light object
Light.Spot light =
new
Light.Spot();
// set coordinate of direction
// the vector of this light
light.setPointsAtX(
0
);
light.setPointsAtY(
0
);
light.setPointsAtZ(-
60
);
// set specular exponent
light.setSpecularExponent(
2
);
// set color of light
light.setColor(Color.RED);
// set coordinates
light.setX(
100
);
light.setY(
100
);
light.setZ(
200
);
// create a lighting
Lighting lighting =
new
Lighting();
// set Light of lighting
lighting.setLight(light);
// create a rectangle
Rectangle rect =
new
Rectangle(
250
,
250
);
// set fill
rect.setFill(Color.WHITE);
// set effect
rect.setEffect(lighting);
// create a Group
Group group =
new
Group(rect);
// create a scene
Scene scene =
new
Scene(group,
500
,
300
);
// set the scene
stage.setScene(scene);
stage.show();
}
// Main Method
public
static
void
main(String args[])
{
// launch the application
launch(args);
}
}
输出:
注: 上述程序可能无法在联机IDE中运行。请使用脱机编译器。
参考: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/Light.Spot.html
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END