|
Post by krotus on Apr 9, 2020 23:19:50 GMT
I have successfully mapped an image onto a sphere:
What I cannot seem to do is rotate the sphere or texture map or pattern or spherical map or whichever or whatever combination on the Y axis to get a different look at the geography. And not just the image map - I can't rotate the checker pattern from the bonus chapter either. But if I apply the stripe pattern from Chapter 10, I can scale it and rotate in the Z axis to make horizontal stripes. Any suggestions?
BTW, I should mention that I can get a different view by changing my "From" camera view. I'm just wondering if this is actually the solution rather than being able to rotate the sphere; while it works with a single sphere it's obviously not going to work with multiple mapped spheres.
|
|
|
Post by krotus on Apr 10, 2020 9:00:49 GMT
I've gone over the bonus chapter on texture mapping the checkers and the image map several times. Maybe I'm still missing something, I don't know. Maybe I botched my Chapter 10 code in way that allowed all tests to pass. In any case, I seem to have solved the issue (to my satisfaction, at least!).
I went back to Chapter 10's "Transforming Patterns" section because the behavior I was seeing, as described in my original post, was consistent with the description of a point being a "world space" point that I was passing to spherical_map() to get my (U, V) point.
In Chapter 10 we created a function called stripe_at_object() that converted the world space point to an object point. I did not see anything in the bonus chapter for us to do that with our point being passed to spherical_map().
I used the code from stripe_at_object() by adding the code to pattern_at() and using the point passed to pattern_at() as the point to convert and pass to spherical_map():
Before I added the code from stripe_at_object() based on the pseudocode from the bonus chapter:
Public Shared Function PatternAt(MyPattern As TextureMap, MyPoint As Tuple(Of Double, Double, Double, Double)) As Tuple(Of Double, Double, Double, Double)
Dim MyColor As Tuple(Of Double, Double, Double, Double) Dim UV As Tuple(Of Double, Double)
Select Case MyPattern.UVMap.GetType.Name.ToUpper Case "SPHERICALMAP" UV = SphericalMap.SphericalMap(MyPoint) Case "CYLINDRICALMAP" Case "PLANARMAP" End Select
Select Case MyPattern.UVPattern.GetType.Name.ToUpper Case "CHECKERS" MyColor = Checkers.UVPatternAt(MyPattern.UVPattern, UV.Item1, UV.Item2) Case "IMAGE" MyColor = Image.UVPatternAt(MyPattern.UVPattern, UV.Item1, UV.Item2) End Select
Return MyColor
End Function
After I added the code:
Public Shared Function PatternAt(MyPattern As TextureMap, MyShape As Primitive, MyPoint As Tuple(Of Double, Double, Double, Double)) As Tuple(Of Double, Double, Double, Double)
Dim MyColor As Tuple(Of Double, Double, Double, Double) Dim UV As Tuple(Of Double, Double)
'Convert world point to object point Dim MyObjectPoint As Tuple(Of Double, Double, Double, Double) = MyMath.MultiplyMatrixByTuple(MyMath.GetInvertedMatrix(MyShape.Transformation), MyPoint) Dim MyPatternPoint As Tuple(Of Double, Double, Double, Double) = MyMath.MultiplyMatrixByTuple(MyMath.GetInvertedMatrix(MyPattern.Transformation), MyObjectPoint)
Select Case MyPattern.UVMap.GetType.Name.ToUpper Case "SPHERICALMAP" UV = SphericalMap.SphericalMap(MyPatternPoint) Case "CYLINDRICALMAP" Case "PLANARMAP" End Select
Select Case MyPattern.UVPattern.GetType.Name.ToUpper Case "CHECKERS" MyColor = Checkers.UVPatternAt(MyPattern.UVPattern, UV.Item1, UV.Item2) Case "IMAGE" MyColor = Image.UVPatternAt(MyPattern.UVPattern, UV.Item1, UV.Item2) End Select
Return MyColor
End Function
Like I said, I don't know what I missed in the bonus chapter or even in Chapter 10, but this seems to work. It even corrected the issues I was having with the Checkers pattern.
|
|