mirror of
https://github.com/bluefireteam/flutter_and_friends_2025_flame_3d_workshop_template.git
synced 2026-08-12 03:30:54 +02:00
feat: Add rotating light so the details of the teapot can be seen
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/geometry.dart';
|
||||
import 'package:flame_3d/camera.dart';
|
||||
import 'package:flame_3d/components.dart';
|
||||
import 'package:flame_3d/model.dart';
|
||||
import 'package:flame_3d/parser.dart';
|
||||
import 'package:flame_3d/resources.dart';
|
||||
import 'package:flame_3d_workshop_slides/slides/components/slide.dart';
|
||||
import 'package:flame_3d_workshop_slides/slides/components/slide_game.dart';
|
||||
import 'package:flame_3d_workshop_slides/slides/components/slide_text.dart';
|
||||
@@ -39,8 +42,28 @@ class _TeapotModel extends FlameGame {
|
||||
LightComponent.ambient(
|
||||
intensity: 10.0,
|
||||
),
|
||||
_RotatingLight(),
|
||||
ModelComponent(model: teapot),
|
||||
]);
|
||||
return super.onLoad();
|
||||
}
|
||||
}
|
||||
|
||||
class _RotatingLight extends LightComponent {
|
||||
double _angle = 0.0;
|
||||
_RotatingLight()
|
||||
: super.point(
|
||||
intensity: 100.0,
|
||||
position: Vector3(0, _height, 0),
|
||||
);
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
_angle = (_angle + dt) % tau;
|
||||
position.setValues(_radius * sin(_angle), _height, _radius * cos(_angle));
|
||||
super.update(dt);
|
||||
}
|
||||
|
||||
static const _radius = 3.0;
|
||||
static const _height = 0.75;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user