Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

11

11.11.2011, 16:05

genügt es dann einfach die X und Y Rotation in die Kugelkoordinaten umzurechnen und das Ergebniss dann mit der Rotatef-Methode von openGL zu Zeichnen? Und was ist der Up-Vektor?

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

12

11.11.2011, 16:17

Na das sind eben zwei der Parameter von gluLookAt()!?
eye ist die Kameraposition, center ist der Punkt wo die Kamera hinschaut (berechest du aus den Kugelkoordinaten) und up ist ein Vektor, der in die Richtung zeigt, wo für die Kamera "oben" ist (berechnest du aus den Kugelkoordinaten, legt die Rotation der Kamera um die Blickrichtung fest).

13

11.11.2011, 16:29

An gluLookAt hab ich nicht dran gedacht dasses das auch noch gibt. ^^
Also, Danke! Ich werd mal mein Glück versuchen.

14

12.11.2011, 14:43

HI,
also ich habs jetz mal so versucht, jedoch verändert sich, wenn ich die Maus bewege nichts.
was könnte der Grund dafür sein?

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public class CamFP {

    final float pi  = 3.141592f;
    
    Vektor eyeOrigin = new Vektor();
    Vektor eye = new Vektor();
    
    Vektor centerOrigin = new Vektor();
    Vektor center = new Vektor();
    
    Vektor upOrigin = new Vektor();
    Vektor upVector = new Vektor();
    
    float phi;
    float theta;
    float radius;
    
    public CamFP(float eyeX, float eyeY, float eyeZ)
    {
        centerOrigin.x = 0.0f;
        centerOrigin.y = 0.0f;
        centerOrigin.z = 0.0f;
        center = centerOrigin;

        eyeOrigin.x = eyeX;
        eyeOrigin.y = eyeY;
        eyeOrigin.z = eyeZ;
        eye = eyeOrigin;

        upOrigin.x = 0.0f;
        upOrigin.y = 1.0f;
        upOrigin.z = 0.0f;
        upVector = upOrigin;

        cartesianToSpherical();
    }
    
    void calcRadius(){
        radius = (float)Math.sqrt((Math.pow(eye.x,2) + Math.pow(eye.y,2) + Math.pow(eye.z,2)));
    }

    void calcTheta(){
        theta = (float)Math.acos(eye.x / radius);
    }

    void calcPhi(){
        phi = (float)Math.acos( eye.x /(radius * Math.sin(theta) ) );
    }
    
    public float radToDeg(float x)  {
        return x * 180.0f / pi;
    }
    
    public float degToRad(float x)  {
        return x * pi / 180.0f;
    }   
    
    public void rotateY(float degrees)  {
        theta += degrees;
    }
    
    public void rotateZ(float degrees)  {
        phi += degrees;
    }
    
    public void cartesianToSpherical(/*float pEyeX, float pEyeY, float pEyeZ*/){
        calcRadius();
        calcTheta();
        calcPhi();
        eye.x = radius;
        eye.y = theta;
        eye.z = phi;
        eye.y = radToDeg(eye.y);
        eye.z = radToDeg(eye.z);
    }
    
    private void sphericalToCartesian(){
        center.x = radius * (float)Math.cos(phi) * (float)Math.cos(theta);
        center.y = radius * (float)Math.cos(phi) * (float)Math.sin(theta);
        center.z = radius * (float)Math.sin(phi); //should be identical to starting cZ value
    }
    
    public void updateView(){

        sphericalToCartesian();
        center.x = centerOrigin.x - eye.x;
        center.y = centerOrigin.y - eye.y;
        center.z = centerOrigin.z - eye.z;
        float length;

        length = (float)Math.sqrt(Math.pow(center.x, 2) + Math.pow(center.y, 2) + Math.pow(center.z, 2));

        center.x /= length;
        center.y /= length;
        center.z /= length;
    
        GLU.gluLookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, upVector.x, upVector.y, upVector.z);
    }
}

class Vektor{
    float x=0;
    float y=0;
    float z=0;
}


Ich glaube, dass es an dem LookAt liegt, muss ich dafür noch etwas Besonderes aktivieren, dass es funktioniert?

Danke schonmal.

Mfg,
Mick

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »mick1114« (12.11.2011, 14:48)


Werbeanzeige