eu realmente preciso de view e projection? uma vez que apenas quero texturizar a esfera…
- User
eu realmente preciso de view e projection? uma vez que apenas quero texturizar a esfera e fazê-la girar em algum eixo?
import 'dart:async'; import 'dart:typed_data'; import 'dart:ui'; import 'package:flutter/material.dart'; import 'dart:math' as math; import 'dart:ui' as ui; import 'package:vector_math/vector_math_64.dart' hide Colors;
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text('Esfera 3D com Textura Fixa')), body: Center(child: SphereWidget()), backgroundColor: const Color.fromARGB(255, 52, 13, 245), ), ); } }
class SphereWidget extends StatefulWidget { @override _SphereWidgetState createState() => _SphereWidgetState(); }
class _SphereWidgetState extends State { double angle = 0; double rotation = 0; ui.Image? texture;
@override void initState() { super.initState(); loadImageFromAsset('assets/02.jpg'); rotate(); }
void rotate() { Timer.periodic(Duration(milliseconds: 16), (timer) { setState(() { angle += 0.008; // Controle da velocidade de rotação rotation += 0.1; }); }); }
Future loadImageFromAsset(String path) async { final completer = Completer<ui.Image>(); final image = AssetImage(path); image.resolve(ImageConfiguration()).addListener( ImageStreamListener((info, _) { completer.complete(info.image); }), ); texture = await completer.future; setState(() {}); }
@override Widget build(BuildContext context) { if (texture == null) { return Container(); }
/* return Stack( children: [ for (int i = 0; i < 15; i++) Positioned( left: (i % 5) * 200.0, // Distância entre esferas horizontalmente top: (i ~/ 5) * 200.0, // Distância entre esferas verticalmente child: CustomPaint( size: Size(10, 10), painter: SpherePainter(texture!, angle, rotation), ), ), ], ); */ return CustomPaint( size: const Size(100, 100), painter: SpherePainter(texture!, angle, rotation), );} }
class SpherePainter extends CustomPainter { final ui.Image texture; final double angle; final Matrix4 transform = Matrix4.identity(); final Vector3 position = Vector3.zero(); final Vector3 rotation = Vector3.zero(); final Vector3 scale = Vector3(1, 1, 1); double rotacao = 0;
SpherePainter(this.texture, this.angle, this.rotacao);
void updateTransform() { final Matrix4 m = Matrix4.compose( position, Quaternion.euler( radians(rotation.y), radians(rotation.x), radians(rotation.z)), scale); transform.setFrom(m); }
// Função para transformar os vértices com a rotação aplicada void transformVertices( List vertices, Matrix4 model, Matrix4 view, Matrix4 projection, Float32List positions, Float32List positionsZ, ) { final Matrix4 transform = model * view * projection; // Tente esta ordem
for (int i = 0; i < vertices.length; i++) { final Vector4 v = Vector4(vertices[i].x, vertices[i].y, vertices[i].z, 1.0); v.applyMatrix4(transform); final double w = v.w; positions[i * 2] = v.x / w; positions[i * 2 + 1] = v.y / w; positionsZ[i] = v.z / w; } - Assistant
Para texturizar uma esfera e fazê-la girar em um eixo, você não necessariamente precisa de matrizes de view e projection no sentido tradicional usado em computação gráfica 3D. Essas matrizes são geralmente usadas para estabelecer a câmera (view) e a projeção de perspectiva ou ortográfica (projection) do mundo em um viewport 2D.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.