// Thomas Helzle 2005
// Verwenden Sie diesen Code wie immer Sie möchten,
// aber ich übernehme keine Verantwortung für seine Richtigkeit!
// Falls Sie Fehler finden, bitte benachrichtigen Sie mich.
//Zuerst werden einige Variablen definiert:
double Dot = 0.0;
miMatrix* GoalMatrixP;
miVector GoalDirection = {0.0, 0.0, 0.0};
// Nun frage ich die drei Teile der Goal Objekt Referenz vom SPDL ab:
// Das erste ist ein Offset in ein Array von Daten, das nächste ist die Anzahl
// an Objekten im Array und das letzte ist das Object-Tag Array selbst:
// Next retrieve the 3 parts of the Goal object reference from the SPDL:
// The first is an offset into an array of data, the next is the number of
// objects in the array and the last is the array of object-tags itself:
miInteger i_objects = in_pParams->i_objects;
miInteger n_objects = in_pParams->n_objects;
miTag *objects = &in_pParams->objects[i_objects];
// als nächstes hole ich mir die globalen Koordinaten des Goal Objektes mit
// mi_query. Da ich in diesem Fall weiß, daß es nur ein Goal geben kann
// da ich den Object Picker im Single Mode verwende, habe ich es hart auf
// objects[0] gesetzt. Falls Sie eine Mehrfachauswahl verwenden, müssen Sie
// über die Zahl der Objekte in n_objects loopen. // next we retrieve the global coordinates of the Goal object with mi_query.
// Since I know in this case that there is only one Goal, I hardcoded it to
// "objects[0]" instead of a loop over n_objects (I use an object picker
// in "single mode") but be careful if you work with multiple objects!
mi_query(miQ_INST_LOCAL_TO_GLOBAL, NULL, objects[0], &GoalMatrixP)
// Jetzt haben wir die Matrix die unsere Koordinaten enthält, ich brauchen
// aber nur die Position. Wenn man sich die 16 Werte als 4 Zeilen und 4 Reihen
// vorstellt ist die unterste Zeile die Position (nur die ersten drei Werte sind
// in Benutzung. Das Array startet bei [0], also sind [12] - [14] unsere
// X, Y und Z Werte. // Now we have the matrix which contains the coordinates, let's extract
// the position values. If you imagine the 16 values of the matrix as
// 4 rows and 4 columns from left to right and top to bottom, the
// lowest row is the position where only the first three values are used.
// The array starts at [0], so [12]-[14] are our x, y and z values:
GoalDirection.x = (*GoalMatrixP)[12];
GoalDirection.y = (*GoalMatrixP)[13];
GoalDirection.z = (*GoalMatrixP)[14];
// Eines meiner Probleme war der verzwickte "Pointer auf ein Array" und die
// korrekte Klammersetzung. Zuerst hatte ich keine Klammern, aber dann haben
// die eckigen Klammern Vorrang vor dem "Stern".
// Jetzt wandle ich diese Position in den "Internal Space" um:
mi_point_from_world(state, &GoalDirection, &GoalDirection);
// Jetzt ziehe ich die Position des momentanen Sample-Punktes von der Positon des
// Goals ab um den resultierenden Vektor zu erhalten:// Then subtract the current sample points position from the Goal position
// to get the resulting direction vector:
GoalDirection.x -= state->point.x;
GoalDirection.y -= state->point.y;
GoalDirection.z -= state->point.z;
// Dieser Vektor wird nun noch normalisiert, seine "Länge" also auf 1.0 gesetzt:// This vector is then "normalized" which means that it's length is set to 1.0
mi_vector_normalize(&GoalDirection);
// Zum Schluß berechne ich das Dot Produkt zwischen der Oberflächennormalen
// und der Goal Richtung und bringe das ganze noch in eine angenehme Form zur
// Weiterverarbeitung, also in einen Bereich zwischen 0.0 und 1.0. Sonst wäre es
// zwischen -1.0 und 1.0: // And finally the Dot product between the surface normal and the GoalDirection
// is taken and modified a bit for an easy to use direction value between 0 and 1.
// Otherwise it would be between -1 and 1.
Dot = (mi_vector_dot(&state->normal, &GoalDirection) + 1.0) * 0.5;
// So, das war's, das Ergebnis kann nun beliebig eingesetzt werde - Viel Spaß! :-)
