Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

looking for an object.fill "mirror" method
Started by sporkfin Apr 17 2018 09:58 AM

10 replies to this topic

Best Answer sporkfin , 19 April 2018 - 02:36 AM

OK, I solved this by normalizing the landscapes so that the overall dimensions of each landscape are identical.  At some point I will try to do the mathematical fix and figure out the best way to adjust the fill x and y.

 

Thanks @nick_sherman, @davebollinger, @sgs for the tips.  While the answer involved a more base problem that I had failed to identify, I learned some new tricks from playing around with your suggestions.  Now I have several answers to problems that don't exist for me. . . yet!  ;)

 

texture_wrap_fix.gif

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 489 posts
  • Corona SDK

I have 2 large landscapes that meet to form an annoying and visible line.  Each landscape is a display.newPolygon with an object.fill that is a textured wrapped bitmap image.  I'm hoping to mirror one of the landscapes to facilitate a smooth transition. 

object.fill.rotation

object.fill.rotation only rotates the fill and I need a mirrored effect.  I'm hoping to achieve this without having to use another bitmap that has been manually mirrored.

 

Any ideas?



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,780 posts
  • Corona SDK

Haven't tried this but setting .xScale to -1 might work?

[TOPIC: post.html]
#3

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,333 posts
  • Enterprise

as per nick_sherman, either

object.xScale = -1

or

object.fill.scaleX = -1

(no idea why they didn't keep consistent property naming)



[TOPIC: post.html]
#4

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 489 posts
  • Corona SDK

Now that's a nifty trick guys!  I've never tried that.  It worked fine on some little tests I did but, unfortunately, it doesn't seem to work for my landscapes and I think it has something to do with the texture wrapping.  I'll keep investigating.



[TOPIC: post.html]
#5

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,073 posts
  • Corona SDK

Can you not use setDefault() to do this?

 

display.setDefault( "textureWrapX", "repeat" )
display.setDefault( "textureWrapY", "mirroredRepeat" )

 

https://docs.coronalabs.com/guide/graphics/repeatFill.html



[TOPIC: post.html]
#6

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 489 posts
  • Corona SDK

@SGS 

I like that idea.  I forgot there was a mirrored repeat.  I only every us clamp and regular repeat.  I'll give it a shot!



[TOPIC: post.html]
#7

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 489 posts
  • Corona SDK

After further investigation, I have a feeling that both suggested methods would work, however, I think the real problem is that each landscape has it's own fill scaling to keep the texture consistent so only two landscapes with an identical width or height will be easily mirrored.  They would probably also need to each match the bitmap fill file in width or height as well - otherwise the fill might get cropped before it can match it's mirror image.

-- fillSize is the size of the bitmap texture file 512 x 512 in this case.
object.fill.scaleX = fillSize/object.width
object.fill.scaleY = fillSize/object.height
I'll think about ways to normalize this that won't require a massive rewrite.  I'll keep it stewing on the backburner for now . . . 


[TOPIC: post.html]
#8

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,073 posts
  • Corona SDK

@spork a visualisation would really help here?

 

I use multiple polygons and apply shaders to those polygons and they play nicely together.

 

Attached File  Image8.png   621.15KB   1 downloads

 

Each "water tile" is a polygon and each has a texture applied and a shader to animate the water.



[TOPIC: post.html]
#9

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,333 posts
  • Enterprise

just negate it:

object.fill.scaleX = -fillSize/object.width


[TOPIC: post.html]
#10

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 489 posts
  • Corona SDK

I think the solution will be to offset the fill of the landscapes with consideration to their height and width variations.

 
object.fill.x = offsetX
object.fill.y = offsetY

That is some math I'm going to save for another day.

 

The suggestions for -xScale and -fillSize were great but since variation in each landscape's dimensions will lead to a different offset of the fill, the great mirroring suggestions don't solve that more basic problem that I failed to take into account - landscape height and width variability (with regard to texture wrapping).

 

I'm attaching an image to illustrate

texture_wrap_524.gif

 

A. texture is applied to a polygon with a wrap (ignore the green "grass")

 

B. In the game environment, when two landscapes meet a hard line between the textures forms

 

C. and D. If the scaling is identical the textures wrap beautifully but if the textures vary in scaling (like the landscapes) the smooth wrap is lost

 

E.  A landscape is generated and paired with it's twin (F.)  They have identical scaling but a hard line forms where they meet.

 

G. Mirroring the bottom landscape visual blends the textures of the two landscapes - removing the hard line.

 

Rather and doing all the math to figure out the varying offset values, I might just normalize the landscapes somehow - keeping all the landscapes variations but capping (or expanding) them to a predictable height and width that corresponds to the base texture file.



[TOPIC: post.html]
#11

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 489 posts
  • Corona SDK

  Best Answer

OK, I solved this by normalizing the landscapes so that the overall dimensions of each landscape are identical.  At some point I will try to do the mathematical fix and figure out the best way to adjust the fill x and y.

 

Thanks @nick_sherman, @davebollinger, @sgs for the tips.  While the answer involved a more base problem that I had failed to identify, I learned some new tricks from playing around with your suggestions.  Now I have several answers to problems that don't exist for me. . . yet!  ;)

 

texture_wrap_fix.gif




[topic_controls]
 
[/topic_controls]