Chaos Project

RPG Maker => RPG Maker Scripts => RMVX Script Database => Topic started by: Blizzard on April 09, 2013, 04:25:21 pm

Title: [VX] Sprite Quaternion Fix
Post by: Blizzard on April 09, 2013, 04:25:21 pm
Sprite Quaternion Fix
Authors: Blizzard
Version: 1.1
Type: Bug Fix
Key Term: Misc Add-on



Introduction

RGSS2Player has a problem with Sprite rotations. If the angle of a sprite is set to an angle that satisfies the condition "ANGLE % 360 == 180", then Game.exe might crash on some PCs, depending on the DirectX DLLs loaded. This mini-script is a workaround for this problem to avoid the crash by setting the Sprite angle to a value very close to the current one, but offset enough to prevent the crash.
This problem happens because of how quaternions work in orientation calculation in 3D space, because quaternions have a conceptual problem that they cannot contain the information if the angle is exactly 180° (instead the quaternion shows that it's 0°).

This work is protected by the following license:
Quote
Creative Commons - Attribution-ShareAlike 3.0 Unported
( http://creativecommons.org/licenses/by-sa/3.0/ )

You are free:

to Share - to copy, distribute and transmit the work
to Remix - to adapt the work
to make commercial use of the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Share alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

With the understanding that:

Waiver - Any of the above conditions can be waived if you get permission from the copyright holder.

Public Domain - Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.

Other Rights - In no way are any of the following rights affected by the license:
- Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
- The author's moral rights;
- Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.

Notice - For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.



Features




Screenshots

N/A for this type of script.


Demo

N/A


Script

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Sprite Quaternion Fix by Blizzard
# Version: 1.1
# Type: Bug Fix
# Date: 9.4.2013
# Date v1.1: 13.4.2013
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Compatibility:
#
#   Should be compatible with anything.
#
#
# Instructions:
#
#   Make a new script above all your other scripts and paste this code into it.
#
#
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#==============================================================================
# Sprite
#==============================================================================

class Sprite

  attr_reader :angle
 
  alias initialize_quaternion_fix_alias initialize
  def initialize(viewport = nil)
    initialize_quaternion_fix_alias(viewport)
    @angle = 0.0
  end
 
  alias angle_assign_quaternion_fix_alias angle=
  def angle=(value)
    if @angle != value
      @angle = value
      value *= 1.00001 if value % 360 == 180 || value % 180 == 90
      angle_assign_quaternion_fix_alias(value)
    end
  end

end



Instructions

Make a new script above all your other scripts and paste this code into it.


Compatibility

Should be compatible with anything.


Credits and Thanks




Author's Notes

If you find any bugs, please report them here:
http://forum.chaos-project.com

That's it! N-Joy! =D
Title: Re: [VX] Sprite Quaternion Fix
Post by: Aegisrox on April 09, 2013, 04:29:42 pm
Amazing Blizzard! Now fixing Enterbrains bugs! Next step, The World!!! xD
Title: Re: [VX] Sprite Quaternion Fix
Post by: Blizzard on April 13, 2013, 11:44:55 am
I updated the script. It seems that it also crashes when assigning 270 as angle when it's already 270.